📄 db_nmhack.cxx
字号:
/* * Copyright (C) 1998, 1999, Jonathan S. Shapiro. * * This file is part of the EROS Operating System. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2, * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#ifndef DB_NO_NMHACK#include <arch-kerninc/db_machdep.hxx> /* data types */#include <ddb/db_sym.hxx>#include <ddb/db_output.hxx>#include <kerninc/util.h>#include <kerninc/SymNames.hxx>/* * An a.out symbol table as loaded into the kernel debugger: * * symtab -> size of symbol entries, in bytes * sp -> first symbol entry * ... * ep -> last symbol entry + 1 * strtab == start of string table * size of string table in bytes, * including this word * -> strings */#ifdef SYMTAB_SPACEint db_symtabsize = SYMTAB_SPACE;int db_symtab[SYMTAB_SPACE/sizeof(int)] = { 0, 1 };#endif/* * Find the symbol table and strings; tell ddb about them. */voidX_db_sym_init(char * symtab, /* pointer to start of symbol table */ char * esymtab, /* pointer to end of string table, for checking - rounded up to integer boundary */ const char * name ){ db_add_symbol_table(symtab, esymtab, name, 0 /* ref */);}db_sym_tX_db_sym_match(db_symtab_t * /*stab */, const char * symstr){ for (uint32_t i = 0; i < FuncSym::count; i++) { const char *rawname = FuncSym::table[i].raw_name; while (*rawname) { if (*rawname == *symstr && (strncmp(rawname, symstr, strlen(symstr)) == 0)) db_printf("%s: %s\n", FuncSym::table[i].name, FuncSym::table[i].raw_name); rawname++; } } return 0;}db_sym_tX_db_lookup(db_symtab_t * /*stab */, const char * symstr){ for (uint32_t i = 0; i < FuncSym::count; i++) { if (strcmp(FuncSym::table[i].raw_name, symstr) == 0) return (db_sym_t) &FuncSym::table[i]; if (strcmp(FuncSym::table[i].name, symstr) == 0) return (db_sym_t) &FuncSym::table[i]; } return 0;}extern "C" { extern int _start; extern int etext; extern int end;}db_sym_tX_db_search_symbol(db_symtab_t * /* symtab */, register db_addr_t off, db_strategy_t /* strategy */, vm_offset_t * diffp) /* in/out */{ uint32_t address = off; uint32_t offset = ~0u; /* maxword */ FuncSym *pEntry = 0; if ( (address < (uint32_t) &_start) || (address >= (uint32_t) &etext) ) return 0; for (uint32_t i = 0; i < FuncSym::count; i++) { if (FuncSym::table[i].address > address) continue; uint32_t newOffset = address - FuncSym::table[i].address; if (newOffset < offset) { pEntry = &FuncSym::table[i]; offset = newOffset; } } *diffp = offset; return (db_sym_t) pEntry;}/* * Return the name and value for a symbol. */voidX_db_symbol_values(db_sym_t sym, const char ** namep, db_expr_t *valuep){ FuncSym *sn = (FuncSym *) sym; if (sn == 0) { *namep = ""; *valuep = 0; } /* printf("sym value \"%s\" @ 0x%08x\n", sn->name, sn->address); */ *namep = sn->name; *valuep = sn->address;}boolX_db_line_at_pc(db_symtab_t * /* symtab */, db_sym_t /* cursym */, const char ** filename, int * linenum, db_expr_t off){ uint32_t address = off; uint32_t offset = ~0u; /* maxword */ LineSym *pEntry = 0; if ( (address < (uint32_t) &_start) || (address >= (uint32_t) &etext) ) return false; for (uint32_t i = 0; i < LineSym::count; i++) { if (LineSym::table[i].address > address) continue; uint32_t newOffset = address - LineSym::table[i].address; if (newOffset < offset) { pEntry = &LineSym::table[i]; offset = newOffset; } } if (pEntry) { *filename = pEntry->file; *linenum = pEntry->line; return true; } else return false;}boolX_db_sym_numargs(db_symtab_t * /* symtab */, db_sym_t /* cursym */, int * nargp, const char ** /* argnamep */){ *nargp = 0; return false;}/* * Initialization routine for a.out files. */voidddb_init(){ X_db_sym_init(0, 0, "nm_table");}#endif /* DB_NO_NMHACK */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -