diff --git a/Makefile b/Makefile index 0327242d..13bcdaf5 100644 --- a/Makefile +++ b/Makefile @@ -105,78 +105,12 @@ DAEMON_OBJECT_FILES=remote_daemon.o va_server.o va_server_v1.o \ lkcd_common.o lkcd_v1.o lkcd_v2_v3.o lkcd_v5.o lkcd_v7.o lkcd_v8.o \ s390_dump.o netdump_daemon.o -GDB_5.0_FILES=${GDB}/gdb/Makefile.in \ - ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ - ${GDB}/gdb/blockframe.c ${GDB}/gdb/alpha-tdep.c \ - ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ - ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/gnu-regex.c \ - ${GDB}/gdb/ppc-linux-nat.c -GDB_5.0_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o ${GDB}/gdb/target.o \ - ${GDB}/gdb/blockframe.o ${GDB}/gdb/alpha-tdep.o \ - ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ - ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o ${GDB}/gdb/gnu-regex.o \ - ${GDB}/gdb/ppc-linux-nat.o - -GDB_5.1_FILES=${GDB}/gdb/Makefile.in \ - ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ - ${GDB}/gdb/blockframe.c ${GDB}/gdb/alpha-tdep.c \ - ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ - ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/gnu-regex.c -GDB_5.1_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o ${GDB}/gdb/target.o \ - ${GDB}/gdb/blockframe.o ${GDB}/gdb/alpha-tdep.o \ - ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ - ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o ${GDB}/gdb/gnu-regex.o - -GDB_5.2.1_FILES=${GDB}/gdb/Makefile.in \ - ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ - ${GDB}/gdb/blockframe.c ${GDB}/gdb/alpha-tdep.c \ - ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ - ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c -GDB_5.2.1_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o ${GDB}/gdb/target.o \ - ${GDB}/gdb/blockframe.o ${GDB}/gdb/alpha-tdep.o \ - ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ - ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o - -GDB_5.3post-0.20021129.36rh_FILES=${GDB}/gdb/Makefile.in \ - ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ - ${GDB}/gdb/frame.c ${GDB}/gdb/alpha-tdep.c \ - ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ - ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/dwarf2read.c -GDB_5.3post-0.20021129.36rh_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o \ - ${GDB}/gdb/target.o ${GDB}/gdb/frame.o ${GDB}/gdb/alpha-tdep.o \ - ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o ${GDB}/gdb/ui-file.o \ - ${GDB}/gdb/utils.o ${GDB}/gdb/dwarf2read.o - -GDB_6.0_FILES=${GDB}/gdb/Makefile.in ${GDB}/Makefile.in \ - ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ - ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ - ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c \ - ${GDB}/gdb/ppc-linux-tdep.c ${GDB}/sim/ppc/ppc-instructions \ - ${GDB}/bfd/simple.c ${GDB}/include/obstack.h -GDB_6.0_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o \ - ${GDB}/gdb/target.o ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ - ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o \ - ${GDB}/gdb/ppc-linux-tdep.o ${GDB}/bfd/simple.o - -GDB_6.1_FILES=${GDB}/gdb/Makefile.in ${GDB}/Makefile.in \ - ${GDB}/gdb/main.c ${GDB}/gdb/symtab.c ${GDB}/gdb/target.c \ - ${GDB}/gdb/symfile.c ${GDB}/gdb/elfread.c \ - ${GDB}/gdb/ui-file.c ${GDB}/gdb/utils.c ${GDB}/gdb/dwarf2read.c \ - ${GDB}/include/obstack.h ${GDB}/gdb/ppc-linux-tdep.c -GDB_6.1_OFILES=${GDB}/gdb/main.o ${GDB}/gdb/symtab.o \ - ${GDB}/gdb/target.o ${GDB}/gdb/symfile.o ${GDB}/gdb/elfread.o \ - ${GDB}/gdb/ui-file.o ${GDB}/gdb/utils.o ${GDB}/gdb/dwarf2read.o \ - ${GDB}/gdb/ppc-linux-tdep.o - -GDB_7.0_FILES= -GDB_7.0_OFILES=${GDB}/gdb/symtab.o - -GDB_7.3.1_FILES= -GDB_7.3.1_OFILES=${GDB}/gdb/symtab.o - GDB_7.6_FILES= GDB_7.6_OFILES=${GDB}/gdb/symtab.o +GDB_7.8_FILES= +GDB_7.8_OFILES=${GDB}/gdb/symtab.o + # # GDB_FLAGS is passed up from the gdb Makefile. # @@ -228,6 +162,7 @@ gdb_merge: force @echo "${LDFLAGS} -lz -ldl -rdynamic" > ${GDB}/gdb/mergelibs @echo "../../${PROGRAM} ../../${PROGRAM}lib.a" > ${GDB}/gdb/mergeobj @rm -f ${PROGRAM} + @ln -sf ${GDB}/gdb/ gdb @if [ ! -f ${GDB}/config.status ]; then \ (cd ${GDB}; ./configure ${GDB_CONF_FLAGS} --with-separate-debug-dir=/usr/lib/debug \ --with-bugurl="" --with-expat=no --with-python=no; \ diff --git a/alpha.c b/alpha.c index fa2d5f59..aa7c2715 100644 --- a/alpha.c +++ b/alpha.c @@ -751,6 +751,7 @@ alpha_dump_line_number(char *name, ulong callpc) static void alpha_frame_offset(struct gnu_request *req, ulong alt_pc) { + static int gdb_frame_offset_warnings = 10; uint *ip, ival; ulong value; @@ -796,15 +797,11 @@ alpha_frame_offset(struct gnu_request *req, ulong alt_pc) } use_gdb: -#ifndef GDB_5_3 -{ - static int gdb_frame_offset_warnings = 10; if (gdb_frame_offset_warnings-- > 0) error(WARNING, "GNU_ALPHA_FRAME_OFFSET functionality not ported to gdb\n"); -} -#endif + req->command = GNU_ALPHA_FRAME_OFFSET; if (alt_pc) { ulong pc_save; diff --git a/configure.c b/configure.c index f329f0c5..f2db4187 100644 --- a/configure.c +++ b/configure.c @@ -57,6 +57,10 @@ #include #include +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) +#endif + struct supported_gdb_version; void build_configure(struct supported_gdb_version *); void release_configure(char *, struct supported_gdb_version *); @@ -158,16 +162,6 @@ void add_extra_lib(char *); * unless overridden. */ -#define GDB_5_3 (0) -#define GDB_6_0 (1) -#define GDB_6_1 (2) -#define GDB_7_0 (3) -#define GDB_7_3_1 (4) -#define GDB_7_6 (5) -#define SUPPORTED_GDB_VERSIONS (GDB_7_6 + 1) - -int default_gdb = GDB_7_6; - struct supported_gdb_version { char *GDB; char *GDB_VERSION_IN; @@ -176,52 +170,7 @@ struct supported_gdb_version { char *GDB_PATCH_FILES; char *GDB_FLAGS; char *GPL; -} supported_gdb_versions[SUPPORTED_GDB_VERSIONS] = { - { - "GDB=gdb-5.3post-0.20021129.36rh", - "Red Hat Linux (5.3post-0.20021129.36rh)", - "GDB_FILES=${GDB_5.3post-0.20021129.36rh_FILES}", - "GDB_OFILES=${GDB_5.3post-0.20021129.36rh_OFILES}", - "GDB_PATCH_FILES=", - "GDB_FLAGS=-DGDB_5_3", - "GPLv2" - }, - { - "GDB=gdb-6.0", - "6.0", - "GDB_FILES=${GDB_6.0_FILES}", - "GDB_OFILES=${GDB_6.0_OFILES}", - "GDB_PATCH_FILES=", - "GDB_FLAGS=-DGDB_6_0", - "GPLv2" - }, - { - "GDB=gdb-6.1", - "6.1", - "GDB_FILES=${GDB_6.1_FILES}", - "GDB_OFILES=${GDB_6.1_OFILES}", - "GDB_PATCH_FILES=gdb-6.1.patch", - "GDB_FLAGS=-DGDB_6_1", - "GPLv2" - }, - { - "GDB=gdb-7.0", - "7.0", - "GDB_FILES=${GDB_7.0_FILES}", - "GDB_OFILES=${GDB_7.0_OFILES}", - "GDB_PATCH_FILES=gdb-7.0.patch", - "GDB_FLAGS=-DGDB_7_0", - "GPLv3" - }, - { - "GDB=gdb-7.3.1", - "7.3.1", - "GDB_FILES=${GDB_7.3.1_FILES}", - "GDB_OFILES=${GDB_7.3.1_OFILES}", - "GDB_PATCH_FILES=gdb-7.3.1.patch", - "GDB_FLAGS=-DGDB_7_3_1", - "GPLv3" - }, +} supported_gdb_versions[] = { { "GDB=gdb-7.6", "7.6", @@ -231,8 +180,19 @@ struct supported_gdb_version { "GDB_FLAGS=-DGDB_7_6", "GPLv3" }, + { + "GDB=gdb-7.8", + "7.8", + "GDB_FILES=${GDB_7.8_FILES}", + "GDB_OFILES=${GDB_7.8_OFILES}", + "GDB_PATCH_FILES=gdb-7.8.patch", + "GDB_FLAGS=-DGDB_7_8", + "GPLv3" + }, }; +struct supported_gdb_version *default_gdb = &supported_gdb_versions[0]; + #define DAEMON 0x1 #define QUIET 0x2 @@ -1367,6 +1327,8 @@ setup_gdb_defaults(void) } while (fgets(inbuf, 512, fp)) { + int i; + strip_linefeeds(inbuf); strip_beginning_whitespace(inbuf); @@ -1375,43 +1337,19 @@ setup_gdb_defaults(void) /* * Simple override. */ - if (strcmp(buf, "5.3") == 0) { - fclose(fp); - sp = &supported_gdb_versions[GDB_5_3]; - fprintf(stderr, ".gdb configuration: %s\n\n", sp->GDB_VERSION_IN); - return store_gdb_defaults(sp); - } - if (strcmp(buf, "6.0") == 0) { - fclose(fp); - sp = &supported_gdb_versions[GDB_6_0]; - fprintf(stderr, ".gdb configuration: %s\n\n", sp->GDB_VERSION_IN); - return store_gdb_defaults(sp); - } - if (strcmp(buf, "6.1") == 0) { - fclose(fp); - sp = &supported_gdb_versions[GDB_6_1]; - fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); - return store_gdb_defaults(sp); - } - if (strcmp(buf, "7.0") == 0) { - fclose(fp); - sp = &supported_gdb_versions[GDB_7_0]; - fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); - return store_gdb_defaults(sp); - } - if (strcmp(buf, "7.3.1") == 0) { - fclose(fp); - sp = &supported_gdb_versions[GDB_7_3_1]; - fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); - return store_gdb_defaults(sp); - } - if (strcmp(buf, "7.6") == 0) { - fclose(fp); - sp = &supported_gdb_versions[GDB_7_6]; - fprintf(stderr, ".gdb configuration: %s\n", sp->GDB_VERSION_IN); - return store_gdb_defaults(sp); - } + for (i = 0; i < ARRAY_SIZE(supported_gdb_versions); i++) { + struct supported_gdb_version *vers; + vers = &supported_gdb_versions[i]; + + if (strcmp(buf, vers->GDB_VERSION_IN) == 0) { + fclose(fp); + sp = vers; + fprintf(stderr, ".gdb configuration: %s\n", + sp->GDB_VERSION_IN); + return store_gdb_defaults(sp); + } + } } fclose(fp); @@ -1424,7 +1362,7 @@ struct supported_gdb_version * store_gdb_defaults(struct supported_gdb_version *sp) { if (!sp) - sp = &supported_gdb_versions[default_gdb]; + sp = default_gdb; else fprintf(stderr, "WARNING: \"make clean\" may be required before rebuilding\n\n"); diff --git a/crash.c b/crash.c new file mode 100644 index 00000000..0345a928 --- /dev/null +++ b/crash.c @@ -0,0 +1,722 @@ +#ifdef CRASH_MERGE +#include "gdb/defs.h" +#include "block.h" +#include "symtab.h" +#include "symfile.h" +#include "command.h" +#include "expression.h" +#include "objfiles.h" +#include "value.h" +#include "top.h" +#include "gdb-stabs.h" +#include "interps.h" +#include "version.h" +#define GDB_COMMON +#include "../../defs.h" +#include "../../crash.h" + +static ulong gdb_merge_flags = 0; +#define KERNEL_SYMBOLS_PATCHED (0x1) + +#ifndef BMSYMBOL_VALUE_ADDRESS +#define BMSYMBOL_VALUE_ADDRESS(a) SYMBOL_VALUE_ADDRESS(a.minsym) +#endif + +#ifndef MSYMBOL_LINKAGE_NAME +#define MSYMBOL_LINKAGE_NAME(msym) SYMBOL_LINKAGE_NAME(msym) +#endif + +#ifndef SET_MSYMBOL_VALUE_ADDRESS +#define SET_MSYMBOL_VALUE_ADDRESS(msym, addr) \ +do { \ + SYMBOL_VALUE_ADDRESS(msym) = addr; \ +} while (0) +#endif + +#ifdef GDB_7_6 +#define prettyformat_structs prettyprint_structs +#define prettyformat_arrays prettyprint_arrays +#define objfile_name(objfile) ((objfile)->name) + +/* gdb 7.8 returns a bound_minimal_symbol. We can fake it here. */ +static struct bound_minimal_symbol +bound_lookup_minimal_symbol(const char *name, const char *sfile, + struct objfile *objf) +{ + struct bound_minimal_symbol bmsym = { + .objfile = objf, + }; + + bmsym.minsym = lookup_minimal_symbol(name, sfile, objf); + + return bmsym; +} +#define lookup_minimal_symbol(a,b,c) bound_lookup_minimal_symbol(a,b,c) +#endif + +#undef STREQ +#define STREQ(A, B) (A && B && (strcmp(A, B) == 0)) +/* + * Given a PC value, return the file and line number. + */ +static void +gdb_get_line_number(struct gnu_request *req) +{ + struct symtab_and_line sal; + struct symbol *sym; + CORE_ADDR pc; + +#define LASTCHAR(s) (s[strlen(s)-1]) + + /* + * Prime the addrmap pump. + */ + if (req->name) + sym = lookup_symbol(req->name, 0, VAR_DOMAIN, 0); + + pc = req->addr; + + sal = find_pc_line(pc, 0); + + if (!sal.symtab) { + req->buf[0] = '\0'; + return; + } + + if (sal.symtab->filename && sal.symtab->dirname) { + if (sal.symtab->filename[0] == '/') + sprintf(req->buf, "%s: %d", + sal.symtab->filename, sal.line); + else + sprintf(req->buf, "%s%s%s: %d", + sal.symtab->dirname, + LASTCHAR(sal.symtab->dirname) == '/' ? "" : "/", + sal.symtab->filename, sal.line); + } +} + +/* + * Walk through a struct type's list of fields looking for the desired + * member field, and when found, return its relevant data. + */ +static void +get_member_data(struct gnu_request *req, struct type *type) +{ + register short i; + struct field *nextfield; + short nfields; + struct type *typedef_type; + + req->member_offset = -1; + + nfields = TYPE_MAIN_TYPE(type)->nfields; + nextfield = TYPE_MAIN_TYPE(type)->flds_bnds.fields; + + if (nfields == 0) { + struct type *newtype; + newtype = lookup_transparent_type(req->name); + if (newtype) { + console("get_member_data(%s.%s): switching type from %lx to %lx\n", + req->name, req->member, type, newtype); + nfields = TYPE_MAIN_TYPE(newtype)->nfields; + nextfield = TYPE_MAIN_TYPE(newtype)->flds_bnds.fields; + } + } + + for (i = 0; i < nfields; i++) { + if (STREQ(req->member, nextfield->name)) { + req->member_offset = nextfield->loc.bitpos; + req->member_length = TYPE_LENGTH(nextfield->type); + req->member_typecode = TYPE_CODE(nextfield->type); + if ((req->member_typecode == TYPE_CODE_TYPEDEF) && + (typedef_type = check_typedef(nextfield->type))) + req->member_length = TYPE_LENGTH(typedef_type); + return; + } + nextfield++; + } +} + +/* + * More robust enum list dump that gdb's, showing the value of each + * identifier, each on its own line. + */ +static void +dump_enum(struct type *type, struct gnu_request *req) +{ + register int i; + int len; + long long lastval; + + len = TYPE_NFIELDS (type); + lastval = 0; + if (TYPE_TAG_NAME(type)) + fprintf_filtered(gdb_stdout, + "enum %s {\n", TYPE_TAG_NAME (type)); + else + fprintf_filtered(gdb_stdout, "enum {\n"); + + for (i = 0; i < len; i++) { + fprintf_filtered(gdb_stdout, " %s", + TYPE_FIELD_NAME (type, i)); + if (lastval != TYPE_FIELD_ENUMVAL (type, i)) { + fprintf_filtered (gdb_stdout, " = %s", + plongest(TYPE_FIELD_ENUMVAL (type, i))); + lastval = TYPE_FIELD_ENUMVAL (type, i); + } else + fprintf_filtered(gdb_stdout, " = %s", plongest(lastval)); + fprintf_filtered(gdb_stdout, "\n"); + lastval++; + } + if (TYPE_TAG_NAME(type)) + fprintf_filtered(gdb_stdout, "};\n"); + else + fprintf_filtered(gdb_stdout, "} %s;\n", req->name); +} + +/* + * Given an enum type with no tagname, determine its value. + */ +static void +eval_enum(struct type *type, struct gnu_request *req) +{ + register int i; + int len; + int lastval; + + len = TYPE_NFIELDS (type); + lastval = 0; + + for (i = 0; i < len; i++) { + if (lastval != TYPE_FIELD_BITPOS (type, i)) { + lastval = TYPE_FIELD_BITPOS (type, i); + } + if (STREQ(TYPE_FIELD_NAME(type, i), req->name)) { + req->tagname = "(unknown)"; + req->value = lastval; + return; + } + lastval++; + } +} + +/* + * General purpose routine for determining datatypes. + */ +static void +gdb_get_datatype(struct gnu_request *req) +{ + register struct cleanup *old_chain = NULL; + register struct type *type; + register struct type *typedef_type; + struct expression *expr; + struct symbol *sym; + register int i; + struct field *nextfield; + struct value *val; + + if (gdb_CRASHDEBUG(2)) + console("gdb_get_datatype [%s] (a)\n", req->name); + + req->typecode = TYPE_CODE_UNDEF; + + /* + * lookup_symbol() will pick up struct and union names. + */ + sym = lookup_symbol(req->name, 0, STRUCT_DOMAIN, 0); + if (sym) { + req->typecode = TYPE_CODE(sym->type); + req->length = TYPE_LENGTH(sym->type); + if (req->member) + get_member_data(req, sym->type); + + if (TYPE_CODE(sym->type) == TYPE_CODE_ENUM) { + if (req->flags & GNU_PRINT_ENUMERATORS) + dump_enum(sym->type, req); + } + + return; + } + + /* + * Otherwise parse the expression. + */ + if (gdb_CRASHDEBUG(2)) + console("gdb_get_datatype [%s] (b)\n", req->name); + + expr = parse_expression(req->name); + + old_chain = make_cleanup(free_current_contents, &expr); + + + switch (expr->elts[0].opcode) + { + case OP_VAR_VALUE: + if (gdb_CRASHDEBUG(2)) + console("expr->elts[0].opcode: OP_VAR_VALUE\n"); + type = expr->elts[2].symbol->type; + if (req->flags & GNU_VAR_LENGTH_TYPECODE) { + req->typecode = TYPE_CODE(type); + req->length = TYPE_LENGTH(type); + } + if (TYPE_CODE(type) == TYPE_CODE_ENUM) { + req->typecode = TYPE_CODE(type); + req->value = SYMBOL_VALUE(expr->elts[2].symbol); + req->tagname = (char *)TYPE_TAG_NAME(type); + if (!req->tagname) { + val = evaluate_type(expr); + eval_enum(value_type(val), req); + } + } + break; + + case OP_TYPE: + if (gdb_CRASHDEBUG(2)) + console("expr->elts[0].opcode: OP_TYPE\n"); + type = expr->elts[1].type; + + req->typecode = TYPE_CODE(type); + req->length = TYPE_LENGTH(type); + + if (TYPE_CODE(type) == TYPE_CODE_TYPEDEF) { + req->is_typedef = TYPE_CODE_TYPEDEF; + if ((typedef_type = check_typedef(type))) { + req->typecode = TYPE_CODE(typedef_type); + req->length = TYPE_LENGTH(typedef_type); + type = typedef_type; + } + } + + if (TYPE_CODE(type) == TYPE_CODE_ENUM) { + if (req->is_typedef) + if (req->flags & GNU_PRINT_ENUMERATORS) { + if (req->is_typedef) + fprintf_filtered(gdb_stdout, + "typedef "); + dump_enum(type, req); + } + } + + if (req->member) + get_member_data(req, type); + + break; + + default: + if (gdb_CRASHDEBUG(2)) + console("expr->elts[0].opcode: %d (?)\n", + expr->elts[0].opcode); + break; + + } + + do_cleanups(old_chain); +} + +/* + * Check whether a command exists. If it doesn't, the command will be + * returned indirectly via the error_hook. + */ +static void +gdb_command_exists(struct gnu_request *req) +{ + extern struct cmd_list_element *cmdlist; + register struct cmd_list_element *c; + + req->value = FALSE; + c = lookup_cmd(&req->name, cmdlist, "", 0, 1); + req->value = TRUE; +} + +static void +gdb_function_numargs(struct gnu_request *req) +{ + struct symbol *sym; + + sym = find_pc_function(req->pc); + + if (!sym || TYPE_CODE(sym->type) != TYPE_CODE_FUNC) { + req->flags |= GNU_COMMAND_FAILED; + return; + } + + req->value = (ulong)TYPE_NFIELDS(sym->type); +} + +struct load_module *gdb_current_load_module = NULL; + +static void +gdb_delete_symbol_file(struct gnu_request *req) +{ + register struct objfile *objfile; + + ALL_OBJFILES(objfile) { + if (STREQ(objfile_name(objfile), req->name) || + same_file(objfile_name(objfile), req->name)) { + free_objfile(objfile); + break; + } + } + + if (gdb_CRASHDEBUG(2)) { + fprintf_filtered(gdb_stdout, "current object files:\n"); + ALL_OBJFILES(objfile) + fprintf_filtered(gdb_stdout, " %s\n", objfile_name(objfile)); + } +} + +static void +gdb_add_symbol_file(struct gnu_request *req) +{ + register struct objfile *loaded_objfile = NULL; + register struct objfile *objfile; + register struct minimal_symbol *m; + struct load_module *lm; + int external, subsequent, found; + off_t offset; + ulong value, adjusted; + struct symbol *sym; + struct expression *expr; + struct cleanup *old_chain; + int i; + int allsect = 0; + char *secname; + char buf[80]; + + gdb_current_load_module = lm = (struct load_module *)req->addr; + + req->name = lm->mod_namelist; + gdb_delete_symbol_file(req); + + if ((lm->mod_flags & MOD_NOPATCH) == 0) { + for (i = 0 ; i < lm->mod_sections; i++) { + if (STREQ(lm->mod_section_data[i].name, ".text") && + (lm->mod_section_data[i].flags & SEC_FOUND)) + allsect = 1; + } + + if (!allsect) { + sprintf(req->buf, "add-symbol-file %s 0x%lx %s", lm->mod_namelist, + lm->mod_text_start ? lm->mod_text_start : lm->mod_base, + lm->mod_flags & MOD_DO_READNOW ? "-readnow" : ""); + if (lm->mod_data_start) { + sprintf(buf, " -s .data 0x%lx", lm->mod_data_start); + strcat(req->buf, buf); + } + if (lm->mod_bss_start) { + sprintf(buf, " -s .bss 0x%lx", lm->mod_bss_start); + strcat(req->buf, buf); + } + if (lm->mod_rodata_start) { + sprintf(buf, " -s .rodata 0x%lx", lm->mod_rodata_start); + strcat(req->buf, buf); + } + } else { + sprintf(req->buf, "add-symbol-file %s 0x%lx %s", lm->mod_namelist, + lm->mod_text_start, lm->mod_flags & MOD_DO_READNOW ? + "-readnow" : ""); + for (i = 0; i < lm->mod_sections; i++) { + secname = lm->mod_section_data[i].name; + if ((lm->mod_section_data[i].flags & SEC_FOUND) && + !STREQ(secname, ".text")) { + sprintf(buf, " -s %s 0x%lx", secname, + lm->mod_section_data[i].offset + lm->mod_base); + strcat(req->buf, buf); + } + } + } + } + + if (gdb_CRASHDEBUG(1)) + fprintf_filtered(gdb_stdout, "%s\n", req->buf); + + execute_command(req->buf, FALSE); + + ALL_OBJFILES(objfile) { + if (same_file(objfile_name(objfile), lm->mod_namelist)) { + loaded_objfile = objfile; + break; + } + } + + if (!loaded_objfile) + req->flags |= GNU_COMMAND_FAILED; +} + + +/* + * Walk through all minimal_symbols, patching their values with the + * correct addresses. + */ +static void +gdb_patch_symbol_values(struct gnu_request *req) +{ + struct minimal_symbol *msymbol; + struct objfile *objfile; + + req->name = PATCH_KERNEL_SYMBOLS_START; + patch_kernel_symbol(req, NULL); + + ALL_MSYMBOLS (objfile, msymbol) + { + req->name = (char *)MSYMBOL_LINKAGE_NAME(msymbol); + if (!patch_kernel_symbol(req, msymbol)) { + req->flags |= GNU_COMMAND_FAILED; + break; + } + } + + req->name = PATCH_KERNEL_SYMBOLS_STOP; + patch_kernel_symbol(req, NULL); + + clear_symtab_users(0); + gdb_merge_flags |= KERNEL_SYMBOLS_PATCHED; +} + +extern void gdb_patch_minsymbol_address(struct minimal_symbol *msym, + unsigned long addr); +void gdb_patch_minsymbol_address(struct minimal_symbol *msym, + unsigned long addr) +{ + SET_MSYMBOL_VALUE_ADDRESS(msym, addr); +} + +static void +gdb_get_symbol_type(struct gnu_request *req) +{ + struct expression *expr; + struct value *val; + struct cleanup *old_chain = NULL; + struct type *type; + struct type *target_type; + + req->typecode = TYPE_CODE_UNDEF; + + expr = parse_expression (req->name); + old_chain = make_cleanup (free_current_contents, &expr); + val = evaluate_type (expr); + + type = value_type(val); + + req->type_name = (char *)TYPE_MAIN_TYPE(type)->name; + req->typecode = TYPE_MAIN_TYPE(type)->code; + req->length = type->length; + target_type = TYPE_MAIN_TYPE(type)->target_type; + + if (target_type) { + req->target_typename = (char *)TYPE_MAIN_TYPE(target_type)->name; + req->target_typecode = TYPE_MAIN_TYPE(target_type)->code; + req->target_length = target_type->length; + } + + if (req->member) + get_member_data(req, type); + + do_cleanups (old_chain); +} + +static void +gdb_debug_command(struct gnu_request *req) +{ + +} + +/* + * Only necessary on "patched" kernel symbol sessions, and called only by + * lookup_symbol(), pull a symbol value bait-and-switch operation by altering + * either a data symbol's address value or a text symbol's block start address. + */ +void +gdb_bait_and_switch(char *name, struct symbol *sym) +{ + struct bound_minimal_symbol msym; + struct block *block; + + if (!(gdb_merge_flags & KERNEL_SYMBOLS_PATCHED)) + return; + + msym = lookup_minimal_symbol(name, NULL, symfile_objfile); + if (!msym.minsym) + return; + + if (SYMBOL_CLASS(sym) == LOC_BLOCK) { + block = (struct block *)SYMBOL_BLOCK_VALUE(sym); + BLOCK_START(block) = BMSYMBOL_VALUE_ADDRESS(msym); + } else + SYMBOL_VALUE_ADDRESS(sym) = BMSYMBOL_VALUE_ADDRESS(msym); +} + +#include "valprint.h" + +static void +get_user_print_option_address(struct gnu_request *req) +{ + extern struct value_print_options user_print_options; + + req->addr = 0; + + if (strcmp(req->name, "output_format") == 0) + req->addr = (ulong)&user_print_options.output_format; + if (strcmp(req->name, "print_max") == 0) + req->addr = (ulong)&user_print_options.print_max; + if (strcmp(req->name, "prettyformat_structs") == 0 || + strcmp(req->name, "prettyprint_structs") == 0) + req->addr = (ulong)&user_print_options.prettyformat_structs; + if (strcmp(req->name, "prettyformat_arrays") == 0 || + strcmp(req->name, "prettyprint_arrays") == 0) + req->addr = (ulong)&user_print_options.prettyformat_arrays; + if (strcmp(req->name, "repeat_count_threshold") == 0) + req->addr = (ulong)&user_print_options.repeat_count_threshold; + if (strcmp(req->name, "stop_print_at_null") == 0) + req->addr = (ulong)&user_print_options.stop_print_at_null; + if (strcmp(req->name, "output_radix") == 0) + req->addr = (ulong)&output_radix; +} + +CORE_ADDR crash_text_scope; + +static void +gdb_set_crash_block(struct gnu_request *req) +{ + if (!req->addr) { /* debug */ + crash_text_scope = 0; + return; + } + + if ((req->addr2 = (ulong)block_for_pc(req->addr))) + crash_text_scope = req->addr; + else { + crash_text_scope = 0; + req->flags |= GNU_COMMAND_FAILED; + } +} + +struct block * +gdb_get_crash_block(void) +{ + if (crash_text_scope) + return block_for_pc(crash_text_scope); + else + return NULL; +} + +/* + * All commands from above come through here. + */ +void +gdb_command_funnel(struct gnu_request *req) +{ + struct symbol *sym; + + if (req->command != GNU_VERSION) { + replace_ui_file_FILE(gdb_stdout, req->fp); + replace_ui_file_FILE(gdb_stderr, req->fp); + do_cleanups(all_cleanups()); + } + + switch (req->command) + { + case GNU_VERSION: + req->buf = (char *)version; + break; + + case GNU_PASS_THROUGH: + execute_command(req->buf, + req->flags & GNU_FROM_TTY_OFF ? FALSE : TRUE); + break; + + case GNU_USER_PRINT_OPTION: + get_user_print_option_address(req); + break; + + case GNU_RESOLVE_TEXT_ADDR: + sym = find_pc_function(req->addr); + if (!sym || TYPE_CODE(sym->type) != TYPE_CODE_FUNC) + req->flags |= GNU_COMMAND_FAILED; + break; + + case GNU_DISASSEMBLE: + if (req->addr2) + sprintf(req->buf, "disassemble 0x%lx 0x%lx", + req->addr, req->addr2); + else + sprintf(req->buf, "disassemble 0x%lx", req->addr); + execute_command(req->buf, TRUE); + break; + + case GNU_ADD_SYMBOL_FILE: + gdb_add_symbol_file(req); + break; + + case GNU_DELETE_SYMBOL_FILE: + gdb_delete_symbol_file(req); + break; + + case GNU_GET_LINE_NUMBER: + gdb_get_line_number(req); + break; + + case GNU_GET_DATATYPE: + gdb_get_datatype(req); + break; + + case GNU_GET_SYMBOL_TYPE: + gdb_get_symbol_type(req); + break; + + case GNU_COMMAND_EXISTS: + gdb_command_exists(req); + break; + + case GNU_ALPHA_FRAME_OFFSET: + req->value = 0; + break; + + case GNU_FUNCTION_NUMARGS: + gdb_function_numargs(req); + break; + + case GNU_DEBUG_COMMAND: + gdb_debug_command(req); + break; + + case GNU_PATCH_SYMBOL_VALUES: + gdb_patch_symbol_values(req); + break; + + case GNU_SET_CRASH_BLOCK: + gdb_set_crash_block(req); + break; + + default: + req->flags |= GNU_COMMAND_FAILED; + break; + } +} + +extern initialize_file_ftype _initialize_crash_interp; +extern void main_loop(void *); + +/* + * initialized by _initialize_cli_interp. This obviously depends on + * _initialize_cli_interp running prior to _initialize_crash_interp. + */ +const struct interp_procs *cli_procs; +void +_initialize_crash_interp (void) +{ + struct interp *command_interp, *cli_interp; + static struct interp_procs crash_procs; + crash_procs.init_proc = cli_procs->init_proc; + crash_procs.resume_proc = cli_procs->resume_proc; + crash_procs.suspend_proc = cli_procs->suspend_proc; + crash_procs.exec_proc = cli_procs->exec_proc; + crash_procs.ui_out_proc = cli_procs->ui_out_proc; + crash_procs.set_logging_proc = cli_procs->set_logging_proc; + crash_procs.command_loop_proc = main_loop; + + command_interp = interp_new("crash-command", &crash_procs); + + interp_add(command_interp); +} +#endif diff --git a/crash.h b/crash.h new file mode 100644 index 00000000..e20406be --- /dev/null +++ b/crash.h @@ -0,0 +1,13 @@ +#ifdef CRASH_MERGE +#define GDB_COMMON +#include "defs.h" +#include "symtab.h" +#include "interps.h" +struct ui_file; +void gdb_bait_and_switch(char *, struct symbol *); +struct block *gdb_get_crash_block(void); +extern int gdb_main_entry(int, char **); +extern void replace_ui_file_FILE(struct ui_file *, FILE *); +int crash_validate_source_file(const char *path, FILE *stream, int from_tty); +extern const struct interp_procs *cli_procs; +#endif diff --git a/defs.h b/defs.h index c5f8beec..47af45f5 100644 --- a/defs.h +++ b/defs.h @@ -16,6 +16,8 @@ * GNU General Public License for more details. */ +#ifndef _CRASH_DEFS_H_ +#define _CRASH_DEFS_H_ #ifndef GDB_COMMON #include @@ -2421,11 +2423,7 @@ struct symbol_namespace { struct symbol_table_data { ulong flags; -#ifdef GDB_5_3 - struct _bfd *bfd; -#else struct bfd *bfd; -#endif struct sec *sections; struct syment *symtable; struct syment *symend; @@ -2501,11 +2499,7 @@ struct symbol_table_data { #define SEC_FOUND (0x10000) struct mod_section_data { -#if defined(GDB_5_3) || defined(GDB_6_0) - struct sec *section; -#else struct bfd_section *section; -#endif char name[MAX_MOD_SEC_NAME]; ulong offset; ulong size; @@ -4021,11 +4015,7 @@ struct gnu_request { char *name; ulong length; int typecode; -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) || defined(GDB_7_0) - char *typename; -#else char *type_name; -#endif char *target_typename; ulong target_length; int target_typecode; @@ -4088,20 +4078,6 @@ struct gnu_request { #define TRUE (1) #define FALSE (0) -#ifdef GDB_COMMON -/* - * function prototypes required by modified gdb source files. - */ -int console(char *, ...); -int gdb_CRASHDEBUG(ulong); -int gdb_readmem_callback(ulong, void *, int, int); -void patch_load_module(struct objfile *objfile, struct minimal_symbol *msymbol); -int patch_kernel_symbol(struct gnu_request *); -struct syment *symbol_search(char *); -int gdb_line_number_callback(ulong, ulong, ulong); -int gdb_print_callback(ulong); -#endif - #ifndef GDB_COMMON /* * WARNING: the following type codes are type_code enums from gdb/gdbtypes.h @@ -4113,10 +4089,7 @@ enum type_code { TYPE_CODE_STRUCT, /* C struct or Pascal record */ TYPE_CODE_UNION, /* C union or Pascal variant part */ TYPE_CODE_ENUM, /* Enumeration type */ -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) || defined(GDB_7_0) || defined(GDB_7_3_1) || defined(GDB_7_6) -#if defined(GDB_7_0) || defined(GDB_7_3_1) || defined(GDB_7_6) TYPE_CODE_FLAGS, /* Bit flags type */ -#endif TYPE_CODE_FUNC, /* Function type */ TYPE_CODE_INT, /* Integer type */ @@ -4137,7 +4110,6 @@ enum type_code { /* * NOTE: the remainder of the type codes are not list or used here... */ -#endif }; #define PF_EXITING 0x00000004 /* getting shut down */ @@ -4290,7 +4262,7 @@ void cmd_ipcs(void); /* ipcs.c */ /* * main.c */ -void main_loop(void); +void main_loop(void *); void exec_command(void); struct command_table_entry *get_command_table_entry(char *); void program_usage(int); @@ -4329,7 +4301,6 @@ void dump_build_data(void); #define machdep_init(X) ppc64_init(X) #endif int clean_exit(int); -int untrusted_file(FILE *, char *); char *readmem_function_name(void); char *writemem_function_name(void); @@ -4364,7 +4335,6 @@ void exec_args_input_file(struct command_table_entry *, struct args_input_file * */ int __error(int, char *, ...); #define error __error /* avoid conflict with gdb error() */ -int console(char *, ...); void create_console_device(char *); int console_off(void); int console_on(int); @@ -4485,7 +4455,6 @@ struct rb_node *rb_last(struct rb_root *); * symbols.c */ void symtab_init(void); -char *check_specified_kernel_debug_file(void); void no_debugging_data(int); void get_text_init_space(void); int is_kernel_text(ulong); @@ -4494,7 +4463,6 @@ int is_init_data(ulong value); int is_kernel_text_offset(ulong); int is_rodata(ulong, struct syment **); void datatype_init(void); -struct syment *symbol_search(char *); struct syment *value_search(ulong, ulong *); struct syment *value_search_base_kernel(ulong, ulong *); struct syment *value_search_module(ulong, ulong *); @@ -4574,7 +4542,7 @@ int text_value_cache_byte(ulong, unsigned char *); void dump_text_value_cache(int); void clear_text_value_cache(void); void dump_numargs_cache(void); -int patch_kernel_symbol(struct gnu_request *); +void gdb_patch_minsymbol_address(void *msym, unsigned long addr); struct syment *generic_machdep_value_to_symbol(ulong, ulong *); long OFFSET_verify(long, char *, char *, int, char *); long SIZE_verify(long, char *, char *, int, char *); @@ -4616,7 +4584,7 @@ void clear_vma_cache(void); void dump_vma_cache(ulong); int is_page_ptr(ulong, physaddr_t *); void dump_vm_table(int); -int read_string(ulong, char *, int); +int mem_read_string(ulong, char *, int); void get_task_mem_usage(ulong, struct task_mem_usage *); char *get_memory_size(char *); uint64_t generic_memory_size(void); @@ -4690,7 +4658,7 @@ int file_dump(ulong, ulong, ulong, int, int); #define DUMP_DENTRY_ONLY 4 #define DUMP_EMPTY_FILE 8 #endif /* !GDB_COMMON */ -int same_file(char *, char *); +int same_file(const char *, const char *); #ifndef GDB_COMMON int cleanup_memory_driver(void); @@ -4873,13 +4841,11 @@ void non_matching_kernel(void); struct load_module *modref_to_load_module(char *); int load_module_symbols_helper(char *); void unlink_module(struct load_module *); -int check_specified_module_tree(char *, char *); int is_system_call(char *, ulong); void generic_dump_irq(int); void generic_get_irq_affinity(int); void generic_show_interrupts(int, ulong *); int generic_dis_filter(ulong, char *, unsigned int); -int kernel_BUG_encoding_bytes(void); void display_sys_stats(void); char *get_uptime(char *, ulonglong *); void clone_bt_info(struct bt_info *, struct bt_info *, struct task_context *); @@ -5991,15 +5957,11 @@ void get_gdb_version(void); void gdb_session_init(void); void gdb_interface(struct gnu_request *); int gdb_pass_through(char *, FILE *, ulong); -int gdb_readmem_callback(ulong, void *, int, int); -int gdb_line_number_callback(ulong, ulong, ulong); -int gdb_print_callback(ulong); void gdb_error_hook(void); void restore_gdb_sanity(void); int is_gdb_command(int, ulong); char *gdb_command_string(int, char *, int); void dump_gnu_request(struct gnu_request *, int); -int gdb_CRASHDEBUG(ulong); void dump_gdb_data(void); void update_gdb_hooks(void); void gdb_readnow_warning(void); @@ -6016,78 +5978,34 @@ extern unsigned int *gdb_output_radix; * gdb/top.c */ extern void execute_command (char *, int); -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) -extern void (*command_loop_hook)(void); -extern void (*error_hook)(void); -#else extern void (*deprecated_command_loop_hook)(void); /* * gdb/exceptions.c */ extern void (*error_hook)(void); -#endif - -/* - * gdb/symtab.c - */ -extern void gdb_command_funnel(struct gnu_request *); - -/* - * gdb/symfile.c - */ -#if defined(GDB_6_0) || defined(GDB_6_1) -struct objfile; -extern void (*target_new_objfile_hook)(struct objfile *); -#endif /* * gdb/valprint.c */ extern unsigned output_radix; -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) -extern int output_format; -extern int prettyprint_structs; -extern int prettyprint_arrays; -extern int repeat_count_threshold; -extern unsigned int print_max; -extern int stop_print_at_null; -#endif -#ifdef GDB_7_6 /* * gdb/cleanups.c */ struct cleanup; extern struct cleanup *all_cleanups(void); extern void do_cleanups(struct cleanup *); -#else -/* - * gdb/utils.c - */ -extern void do_cleanups(void *); -#endif /* * gdb/version.c */ extern char *version; -/* - * gdb/disasm.c - */ -#ifdef GDB_5_3 -extern int gdb_disassemble_from_exec; -#endif - /* * readline/readline.c */ -#ifdef GDB_5_3 -extern char *readline(char *); -#else extern char *readline(const char *); -#endif extern int rl_editing_mode; /* @@ -6099,11 +6017,7 @@ extern int history_offset; * external gdb routines */ extern int gdb_main_entry(int, char **); -#ifdef GDB_5_3 -extern unsigned long calc_crc32(unsigned long, unsigned char *, size_t); -#else extern unsigned long gnu_debuglink_crc32 (unsigned long, unsigned char *, size_t); -#endif extern int have_partial_symbols(void); extern int have_full_symbols(void); @@ -6112,3 +6026,24 @@ extern int have_full_symbols(void); #endif #endif /* !GDB_COMMON */ + +/* + * function prototypes required by modified gdb source files. + */ +int console(char *, ...); +int gdb_CRASHDEBUG(ulong); +int gdb_readmem_callback(ulong, void *, int, int); +struct objfile; +struct minimal_symbol; +void patch_load_module(struct objfile *objfile, struct minimal_symbol *msymbol); +int patch_kernel_symbol(struct gnu_request *, void *msym); +struct syment *symbol_search(char *); +int gdb_line_number_callback(ulong, ulong, ulong); +int gdb_print_callback(ulong); +int untrusted_file(FILE *, const char *); +char *check_specified_kernel_debug_file(void); +int check_specified_module_tree(const char *, char *); +void gdb_command_funnel(struct gnu_request *); +int kernel_BUG_encoding_bytes(void); + +#endif /* _CRASH_DEFS_H_ */ diff --git a/dev.c b/dev.c index c18f40ec..f9fa3198 100644 --- a/dev.c +++ b/dev.c @@ -182,7 +182,7 @@ dump_chrdevs(ulong flags) fprintf(fp, " %3d ", i); if (cp->name) { - if (read_string(cp->name, buf, BUFSIZE-1)) + if (mem_read_string(cp->name, buf, BUFSIZE-1)) fprintf(fp, "%-11s ", buf); else fprintf(fp, "%-11s ", "(unknown)"); @@ -230,7 +230,7 @@ dump_chrdevs(ulong flags) break; case TYPE_CODE_PTR: default: - if (!name || !read_string(name, buf, BUFSIZE-1)) + if (!name || !mem_read_string(name, buf, BUFSIZE-1)) break; } @@ -301,7 +301,8 @@ dump_chrdevs(ulong flags) break; case TYPE_CODE_PTR: default: - if (!name || !read_string(name, buf, BUFSIZE-1)) + if (!name || + !mem_read_string(name, buf, BUFSIZE-1)) sprintf(buf, "(unknown)"); break; } @@ -455,7 +456,7 @@ dump_blkdevs(ulong flags) fprintf(fp, " %3d ", i); if (bp->name) { - if (read_string(bp->name, buf, BUFSIZE-1)) + if (mem_read_string(bp->name, buf, BUFSIZE-1)) fprintf(fp, "%-11s ", buf); else fprintf(fp, "%-11s ", "(unknown)"); @@ -840,7 +841,7 @@ do_io(void) end += start; fprintf(fp, "%04lx-%04lx ", start, end); name = ULONG(resource_buf + OFFSET(resource_entry_t_name)); - if (!read_string(name, buf1, BUFSIZE-1)) + if (!mem_read_string(name, buf1, BUFSIZE-1)) sprintf(buf1, "(unknown)"); if (wrap + strlen(buf1) <= 80) @@ -932,7 +933,7 @@ do_resource_list(ulong first_entry, char *resource_buf, int size) child = ULONG(resource_buf + OFFSET(resource_child)); sibling = ULONG(resource_buf + OFFSET(resource_sibling)); - if (!read_string(name, buf1, BUFSIZE-1)) + if (!mem_read_string(name, buf1, BUFSIZE-1)) sprintf(buf1, "(unknown)"); fprintf(fp, fmt, entry, start, end); diff --git a/extensions/dminfo.c b/extensions/dminfo.c index 8de3ba56..c4610db1 100644 --- a/extensions/dminfo.c +++ b/extensions/dminfo.c @@ -191,7 +191,7 @@ static struct dminfo_member_entry { #define GET_STR(addr, s, m, ret, len) \ do { \ INIT_MBR_TABLE(s, m); \ - if (!read_string(addr + mbr_ary[DM_##s##_##m].offset, ret, len - 1)) \ + if (!mem_read_string(addr + mbr_ary[DM_##s##_##m].offset, ret, len - 1)) \ fprintf(fp, "%s\n", MSG("ERROR: GET_STR", #s, #m)); \ } while (0) @@ -206,7 +206,7 @@ static struct dminfo_member_entry { readmem(addr + mbr_ary[DM_##s##_##m].offset, KVADDR, &tmp, \ mbr_ary[DM_##s##_##m].size, MSG("GET_PTR_STR", #s, #m),\ FAULT_ON_ERROR);\ - if (!read_string(tmp, ret, len - 1)) \ + if (!mem_read_string(tmp, ret, len - 1)) \ fprintf(fp, "%s\n", MSG("ERROR: GET_PTR_STR", #s, #m));\ } while (0) diff --git a/extensions/trace.c b/extensions/trace.c index a09f6a14..92efcfee 100644 --- a/extensions/trace.c +++ b/extensions/trace.c @@ -488,7 +488,7 @@ static int ftrace_init_current_tracer(void) } read_value(addr, addr, tracer, name); - read_string(addr, tmp, 128); + mem_read_string(addr, tmp, 128); current_tracer_name = strdup(tmp); if (current_tracer_name == NULL) @@ -888,9 +888,9 @@ static int ftrace_init_event_fields(ulong fields_head, int *pnfields, read_value(size, field, ftrace_event_field, size); read_value(is_signed, field, ftrace_event_field, is_signed); - if (!read_string(name_addr, field_name, 128)) + if (!mem_read_string(name_addr, field_name, 128)) goto out_fail; - if (!read_string(type_addr, field_type, 128)) + if (!mem_read_string(type_addr, field_type, 128)) goto out_fail; /* Enlarge fields array when need */ @@ -1008,7 +1008,7 @@ int ftrace_get_event_type_name(ulong call, char *name, int len) "read ftrace_event_call name_addr", RETURN_ON_ERROR)) return -1; - if (!read_string(name_addr, name, len)) + if (!mem_read_string(name_addr, name, len)) return -1; return 0; @@ -1053,7 +1053,7 @@ int ftrace_get_event_type_system(ulong call, char *system, int len) "read ftrace_event_call sys_addr", RETURN_ON_ERROR)) return -1; - if (!read_string(sys_addr, system, len)) + if (!mem_read_string(sys_addr, system, len)) return -1; return 0; @@ -1949,7 +1949,7 @@ static int add_print_address(long address) size_t len; int i; - len = read_string(address, string, sizeof(string)); + len = mem_read_string(address, string, sizeof(string)); if (!len) return -1; diff --git a/filesys.c b/filesys.c index 1896f550..eae8cf98 100644 --- a/filesys.c +++ b/filesys.c @@ -1480,12 +1480,12 @@ show_mounts(ulong one_vfsmount, int flags, struct task_context *namespace_contex KVADDR, &name, sizeof(void *), "file_system_type name", FAULT_ON_ERROR); - if (read_string(name, buf1, BUFSIZE-1)) + if (mem_read_string(name, buf1, BUFSIZE-1)) sprintf(buf3, "%-6s ", buf1); else sprintf(buf3, "unknown "); - if (read_string(devp, buf1, BUFSIZE-1)) + if (mem_read_string(devp, buf1, BUFSIZE-1)) sprintf(buf4, "%s ", mkstring(buf2, devlen, LJUST, buf1)); else @@ -1498,7 +1498,7 @@ show_mounts(ulong one_vfsmount, int flags, struct task_context *namespace_contex fprintf(fp, "%s", buf1); if (VALID_MEMBER(vfsmount_mnt_dirname)) { - if (read_string(dirp, buf1, BUFSIZE-1)) + if (mem_read_string(dirp, buf1, BUFSIZE-1)) fprintf(fp, "%-10s\n", buf1); else fprintf(fp, "%-10s\n", "(unknown)"); @@ -2711,7 +2711,7 @@ nlm_files_dump(void) "nlm_host h_exportent", FAULT_ON_ERROR); if (!client) continue; - if (!read_string(client + OFFSET(svc_client_cl_ident), + if (!mem_read_string(client + OFFSET(svc_client_cl_ident), buf1, BUFSIZE-1)) continue; if (!header_printed) { @@ -3051,7 +3051,7 @@ get_pathname_component(ulong dentry, strcpy(pathbuf, dentry_buf + OFFSET(dentry_d_iname)); else len = 0; - } else if ((read_string(d_name_name, pathbuf, BUFSIZE)) != d_name_len) + } else if ((mem_read_string(d_name_name, pathbuf, BUFSIZE)) != d_name_len) len = 0; return len; @@ -3469,7 +3469,7 @@ monitor_memory(long *freemem_pages, * Determine whether two filenames reference the same file. */ int -same_file(char *f1, char *f2) +same_file(const char *f1, const char *f2) { struct stat stat1, stat2; @@ -4086,7 +4086,7 @@ vfsmount_devname(ulong vfsmnt, char *buf, int maxlen) return buf; } - if (read_string(devp, buf, BUFSIZE-1)) + if (mem_read_string(devp, buf, BUFSIZE-1)) return buf; return buf; diff --git a/gdb-7.6.patch b/gdb-7.6.patch index da6f09bb..63796e76 100644 --- a/gdb-7.6.patch +++ b/gdb-7.6.patch @@ -17,14 +17,32 @@ ./pex-djgpp.$(objext) ./pex-msdos.$(objext) \ ./pex-unix.$(objext) ./pex-win32.$(objext) \ ./putenv.$(objext) \ +--- gdb-7.6/sim/common/gentmap.c.orig ++++ gdb-7.6/sim/common/gentmap.c +@@ -2,6 +2,7 @@ + + #include + #include ++#include + + struct tdefs { + char *symbol; --- gdb-7.6/opcodes/i386-dis.c.orig +++ gdb-7.6/opcodes/i386-dis.c -@@ -11510,6 +11510,10 @@ print_insn (bfd_vma pc, disassemble_info +@@ -39,6 +39,8 @@ + #include "opintl.h" + #include "opcode/i386.h" + #include "libiberty.h" ++#define GDB_COMMON ++#include "../../defs.h" + + #include + +@@ -11510,6 +11510,9 @@ print_insn (bfd_vma pc, disassemble_info threebyte = *++codep; dp = &dis386_twobyte[threebyte]; need_modrm = twobyte_has_modrm[*codep]; + if (dp->name && ((strcmp(dp->name, "ud2a") == 0) || (strcmp(dp->name, "ud2") == 0))) { -+ extern int kernel_BUG_encoding_bytes(void); + codep += kernel_BUG_encoding_bytes(); + } codep++; @@ -106,29 +124,6 @@ break; if (cur_sec == NULL) -@@ -1122,6 +1141,12 @@ symbol_file_add_with_addrs_or_offsets (b - error (_("Not confirmed.")); - - objfile = allocate_objfile (abfd, flags | (mainline ? OBJF_MAINLINE : 0)); -+#ifdef CRASH_MERGE -+ if (add_flags & SYMFILE_MAINLINE) { -+ extern struct objfile *gdb_kernel_objfile; -+ gdb_kernel_objfile = objfile; -+ } -+#endif - - if (parent) - add_separate_debug_objfile (objfile, parent); -@@ -1484,6 +1509,9 @@ find_separate_debug_file (const char *di - VEC (char_ptr) *debugdir_vec; - struct cleanup *back_to; - int ix; -+#ifdef CRASH_MERGE -+ extern int check_specified_module_tree(char *, char *); -+#endif - - /* Set I to max (strlen (canon_dir), strlen (dir)). */ - i = strlen (dir); @@ -1513,6 +1541,15 @@ find_separate_debug_file (const char *di if (separate_debug_file_exists (debugfile, crc32, objfile)) return debugfile; @@ -145,13 +140,12 @@ /* Then try in the global debugfile directories. Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will -@@ -1583,6 +1620,10 @@ find_separate_debug_file_by_debuglink (s +@@ -1583,6 +1620,9 @@ find_separate_debug_file_by_debuglink (s char *debugfile; unsigned long crc32; struct cleanup *cleanups; +#ifdef CRASH_MERGE + char *name_copy; -+ extern char *check_specified_kernel_debug_file(); +#endif debuglink = get_debug_link_info (objfile, &crc32); @@ -198,18 +192,16 @@ return (*objfile->sf->sym_relocate) (objfile, sectp, buf); --- gdb-7.6/gdb/cli/cli-cmds.c.orig +++ gdb-7.6/gdb/cli/cli-cmds.c -@@ -466,6 +466,10 @@ show_script_ext_mode (struct ui_file *fi - If SEARCH_PATH is non-zero, and the file isn't found in cwd, - search for it in the source search path. */ +@@ -468,7 +468,7 @@ show_script_ext_mode (struct ui_file *fi -+#ifdef CRASH_MERGE -+static int crash_from_tty = 0; -+#endif -+ int find_and_open_script (const char *script_file, int search_path, - FILE **streamp, char **full_pathp) -@@ -508,6 +512,32 @@ find_and_open_script (const char *script +- FILE **streamp, char **full_pathp) ++ FILE **streamp, char **full_pathp, int from_tty) + { + char *file; + int fd; +@@ -508,6 +512,31 @@ find_and_open_script (const char *script return 0; } @@ -218,7 +210,7 @@ + * Only allow trusted versions of .gdbinit files to be + * sourced during session initialization. + */ -+ if (crash_from_tty == -1) ++ if (from_tty == -1) + { + struct stat statbuf; + FILE *stream = *streamp; @@ -231,7 +223,6 @@ + } + if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH)) + { -+ extern void untrusted_file(FILE *, char *); + untrusted_file(NULL, *full_pathp); + fclose (stream); + return 0; @@ -242,7 +233,15 @@ return 1; } -@@ -566,7 +596,11 @@ source_script_with_search (const char *f +@@ -585,13 +585,18 @@ source_script_with_search (const char *f + if (file == NULL || *file == 0) + error (_("source command requires file name of file to source.")); + +- if (!find_and_open_script (file, search_path, &stream, &full_path)) ++ if (!find_and_open_script (file, search_path, &stream, &full_path, ++ from_tty)) + { + /* The script wasn't found, or was otherwise inaccessible. If the source command was invoked interactively, throw an error. Otherwise (e.g. if it was invoked by a script), silently ignore the error. */ @@ -254,31 +253,36 @@ perror_with_name (file); else return; -@@ -589,7 +623,14 @@ source_script_with_search (const char *f - void - source_script (char *file, int from_tty) - { -+#ifdef CRASH_MERGE -+ crash_from_tty = from_tty; -+#endif - source_script_with_search (file, from_tty, 0); -+#ifdef CRASH_MERGE -+ crash_from_tty = 0; -+#endif -+ +--- gdb-7.6.orig/gdb/cli/cli-interp.c ++++ gdb-7.6/gdb/cli/cli-interp.c +@@ -230,3 +230,24 @@ _initialize_cli_interp (void) + + interp_add (cli_interp); } - - /* Return the source_verbose global variable to its previous state ++ ++extern void main_loop(void *); ++extern initialize_file_ftype _initialize_crash_interp; ++void ++_initialize_crash_interp (void) ++{ ++ struct interp *command_interp; ++ static struct interp_procs crash_procs = { ++ .init_proc = cli_interpreter_init, ++ .resume_proc = cli_interpreter_resume, ++ .suspend_proc = cli_interpreter_suspend, ++ .exec_proc = cli_interpreter_exec, ++ .ui_out_proc = cli_ui_out, ++ .set_logging_proc = NULL, ++ .command_loop_proc = main_loop, ++ }; ++ ++ command_interp = interp_new("crash-command", &crash_procs); ++ ++ interp_add(command_interp); ++} --- gdb-7.6/gdb/psymtab.c.orig +++ gdb-7.6/gdb/psymtab.c -@@ -305,10 +305,14 @@ find_pc_sect_psymtab (struct objfile *ob - struct minimal_symbol *msymbol) - { - struct partial_symtab *pst; -+#ifdef CRASH_MERGE -+ extern int gdb_line_number_callback(unsigned long, unsigned long, unsigned long); -+#endif - +@@ -305,6 +305,7 @@ find_pc_sect_psymtab (struct objfile *ob /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity than the later used TEXTLOW/TEXTHIGH one. */ @@ -351,7 +355,7 @@ return lookup_symbol_in_language (name, block, domain, current_language->la_language, is_a_field_of_this); -@@ -5100,3 +5115,662 @@ When enabled, debugging messages are pri +@@ -5100,3 +5115,666 @@ When enabled, debugging messages are pri observer_attach_executable_changed (symtab_observer_executable_changed); } @@ -380,8 +384,6 @@ +static void gdb_set_crash_block(struct gnu_request *); +void gdb_command_funnel(struct gnu_request *); + -+struct objfile *gdb_kernel_objfile = { 0 }; -+ +static ulong gdb_merge_flags = 0; +#define KERNEL_SYMBOLS_PATCHED (0x1) + @@ -645,7 +647,7 @@ +{ + register int i; + int len; -+ int lastval; ++ long long lastval; + + len = TYPE_NFIELDS (type); + lastval = 0; @@ -658,12 +660,12 @@ + for (i = 0; i < len; i++) { + fprintf_filtered(gdb_stdout, " %s", + TYPE_FIELD_NAME (type, i)); -+ if (lastval != TYPE_FIELD_BITPOS (type, i)) { -+ fprintf_filtered (gdb_stdout, " = %d", -+ TYPE_FIELD_BITPOS (type, i)); -+ lastval = TYPE_FIELD_BITPOS (type, i); ++ if (lastval != TYPE_FIELD_ENUMVAL (type, i)) { ++ fprintf_filtered (gdb_stdout, " = %s", ++ plongest(TYPE_FIELD_ENUMVAL (type, i))); ++ lastval = TYPE_FIELD_ENUMVAL (type, i); + } else -+ fprintf_filtered(gdb_stdout, " = %d", lastval); ++ fprintf_filtered(gdb_stdout, " = %s", plongest(lastval)); + fprintf_filtered(gdb_stdout, "\n"); + lastval++; + } @@ -875,32 +877,38 @@ + * Walk through all minimal_symbols, patching their values with the + * correct addresses. + */ -+static void ++static void +gdb_patch_symbol_values(struct gnu_request *req) +{ + struct minimal_symbol *msymbol; + struct objfile *objfile; + + req->name = PATCH_KERNEL_SYMBOLS_START; -+ patch_kernel_symbol(req); ++ patch_kernel_symbol(req, NULL); + + ALL_MSYMBOLS (objfile, msymbol) + { + req->name = (char *)msymbol->ginfo.name; -+ req->addr = (ulong)(&SYMBOL_VALUE_ADDRESS(msymbol)); -+ if (!patch_kernel_symbol(req)) { ++ if (!patch_kernel_symbol(req, msymbol)) { + req->flags |= GNU_COMMAND_FAILED; + break; + } + } + + req->name = PATCH_KERNEL_SYMBOLS_STOP; -+ patch_kernel_symbol(req); ++ patch_kernel_symbol(req, NULL); + + clear_symtab_users(0); + gdb_merge_flags |= KERNEL_SYMBOLS_PATCHED; +} + ++extern void gdb_patch_minsymbol_address(struct minimal_symbol *msym, ++ unsigned long addr); ++void gdb_patch_minsymbol_address(struct minimal_symbol *msym, ++ unsigned long addr) ++{ ++ SYMBOL_VALUE_ADDRESS(msym) = addr; ++} +static void +gdb_get_symbol_type(struct gnu_request *req) +{ @@ -953,7 +961,7 @@ + struct block *block; + + if ((gdb_merge_flags & KERNEL_SYMBOLS_PATCHED) && -+ (msym = lookup_minimal_symbol(name, NULL, gdb_kernel_objfile))) { ++ (msym = lookup_minimal_symbol(name, NULL, symfile_objfile))) { + if (sym->aclass == LOC_BLOCK) { + block = (struct block *)SYMBOL_BLOCK_VALUE(sym); + BLOCK_START(block) = SYMBOL_VALUE_ADDRESS(msym); @@ -1067,35 +1075,13 @@ /* Jump to the containing catch_errors() call, communicating REASON to that call via setjmp's return value. Note that REASON can't ---- gdb-7.6/gdb/valprint.h.orig -+++ gdb-7.6/gdb/valprint.h -@@ -152,11 +152,17 @@ extern void print_function_pointer_addre - struct gdbarch *gdbarch, - CORE_ADDR address, - struct ui_file *stream); -- -+#ifdef CRASH_MERGE -+extern int valprint_read_string (CORE_ADDR addr, int len, int width, -+ unsigned int fetchlimit, -+ enum bfd_endian byte_order, gdb_byte **buffer, -+ int *bytes_read); -+#else - extern int read_string (CORE_ADDR addr, int len, int width, - unsigned int fetchlimit, - enum bfd_endian byte_order, gdb_byte **buffer, - int *bytes_read); -+#endif - - extern void val_print_optimized_out (struct ui_file *stream); - --- gdb-7.6/gdb/target.c.orig +++ gdb-7.6/gdb/target.c -@@ -1779,6 +1779,13 @@ target_xfer_partial (struct target_ops * +@@ -1779,6 +1779,12 @@ target_xfer_partial (struct target_ops * int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len) { +#ifdef CRASH_MERGE -+ extern int gdb_readmem_callback(unsigned long, void *, int, int); + if (gdb_readmem_callback(memaddr, (void *)myaddr, len, 0)) + return 0; + else @@ -1104,12 +1090,11 @@ /* Dispatch to the topmost target, not the flattened current_target. Memory accesses check target->to_has_(all_)memory, and the flattened target doesn't inherit those. */ -@@ -1814,6 +1821,13 @@ target_read_stack (CORE_ADDR memaddr, gd +@@ -1814,6 +1821,12 @@ target_read_stack (CORE_ADDR memaddr, gd int target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len) { +#ifdef CRASH_MERGE -+ extern int gdb_readmem_callback(unsigned long, void *, int, int); + if (gdb_readmem_callback(memaddr, (void *)myaddr, len, 1)) + return 0; + else @@ -1120,7 +1105,21 @@ flattened target doesn't inherit those. */ --- gdb-7.6/gdb/printcmd.c.orig +++ gdb-7.6/gdb/printcmd.c -@@ -1001,11 +1001,62 @@ print_command_1 (char *exp, int voidprin +@@ -578,6 +578,13 @@ print_address_symbolic (struct gdbarch * + struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); + make_cleanup (free_current_contents, &filename); + ++#ifdef CRASH_MERGE ++ if (!gdb_print_callback(addr)) { ++ do_cleanups (cleanup_chain); ++ return 0; ++ } ++#endif ++ + if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset, + &filename, &line, &unmapped)) + { +@@ -1001,11 +1008,62 @@ print_command_1 (char *exp, int voidprin } static void @@ -1227,20 +1226,6 @@ exit (0); } -@@ -853,6 +853,13 @@ captured_main (void *data) - } - } - -+#ifdef CRASH_MERGE -+{ -+ extern void update_gdb_hooks(void); -+ update_gdb_hooks(); -+} -+#endif -+ - /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets - GDB retain the old MI1 interpreter startup behavior. Output the - copyright message after the interpreter is installed when it is @@ -880,7 +887,11 @@ captured_main (void *data) processed; it sets global parameters, which are independent of what file you are debugging or what directory you are in. */ @@ -1321,54 +1306,44 @@ + args.argc = argc; + args.argv = argv; + args.use_windows = 0; -+ args.interpreter_p = INTERP_CONSOLE; ++ args.interpreter_p = "crash-command"; + return gdb_main (&args); +} +#endif /* Don't use *_filtered for printing help. We don't want to prompt for continue no matter how small the screen or how much we're going ---- gdb-7.6/gdb/valprint.c.orig -+++ gdb-7.6/gdb/valprint.c -@@ -1768,8 +1768,13 @@ partial_memory_read (CORE_ADDR memaddr, - this function instead? */ - - int -+#ifdef CRASH_MERGE -+valprint_read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit, -+ enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read) -+#else - read_string (CORE_ADDR addr, int len, int width, unsigned int fetchlimit, - enum bfd_endian byte_order, gdb_byte **buffer, int *bytes_read) -+#endif - { - int found_nul; /* Non-zero if we found the nul char. */ - int errcode; /* Errno returned from bad reads. */ -@@ -2472,8 +2477,13 @@ val_print_string (struct type *elttype, - fetchlimit = (len == -1 ? options->print_max : min (len, - options->print_max)); - -+#ifdef CRASH_MERGE -+ errcode = valprint_read_string (addr, len, width, fetchlimit, byte_order, -+ &buffer, &bytes_read); -+#else - errcode = read_string (addr, len, width, fetchlimit, byte_order, - &buffer, &bytes_read); -+#endif - old_chain = make_cleanup (xfree, buffer); - - addr += bytes_read; --- gdb-7.6/gdb/Makefile.in.orig +++ gdb-7.6/gdb/Makefile.in +@@ -405,8 +405,8 @@ SUBDIR_GDBTK_DEPS = $(LIBGUI) $(TCL_DEPS + SUBDIR_GDBTK_LDFLAGS= + SUBDIR_GDBTK_CFLAGS= -DGDBTK + +-CONFIG_OBS= @CONFIG_OBS@ +-CONFIG_SRCS= @CONFIG_SRCS@ ++CONFIG_OBS= @CONFIG_OBS@ crash.o ++CONFIG_SRCS= @CONFIG_SRCS@ ../../crash.c + CONFIG_DEPS= @CONFIG_DEPS@ + CONFIG_LDFLAGS = @CONFIG_LDFLAGS@ + ENABLE_CFLAGS= @ENABLE_CFLAGS@ @@ -422,7 +422,7 @@ CONFIG_UNINSTALL = @CONFIG_UNINSTALL@ # It is also possible that you will need to add -I/usr/include/sys if # your system doesn't have fcntl.h in /usr/include (which is where it # should be according to Posix). -DEFS = @DEFS@ -+DEFS = -DCRASH_MERGE @DEFS@ ++DEFS = -DCRASH_MERGE -DGDB_7_6 @DEFS@ GDB_CFLAGS = -I. -I$(srcdir) -I$(srcdir)/common -I$(srcdir)/config \ -DLOCALEDIR="\"$(localedir)\"" $(DEFS) +@@ -837,7 +837,7 @@ gnulib/import/stddef.in.h gnulib/import/ + common/common-utils.h common/xml-utils.h common/buffer.h common/ptid.h \ + common/format.h common/host-defs.h utils.h common/queue.h common/gdb_string.h \ + common/linux-osdata.h gdb-dlfcn.h auto-load.h probe.h stap-probe.h \ +-gdb_bfd.h sparc-ravenscar-thread.h ppc-ravenscar-thread.h common/linux-btrace.h ++gdb_bfd.h sparc-ravenscar-thread.h ppc-ravenscar-thread.h common/linux-btrace.h crash.h + + # Header files that already have srcdir in them, or which are in objdir. + @@ -934,7 +934,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $ TSOBS = inflow.o @@ -1429,20 +1404,16 @@ observer.h: observer.sh doc/observer.texi ${srcdir}/observer.sh h ${srcdir}/doc/observer.texi observer.h ---- gdb-7.6/gdb/c-lang.c.orig -+++ gdb-7.6/gdb/c-lang.c -@@ -307,7 +307,11 @@ c_get_string (struct value *value, gdb_b - { - CORE_ADDR addr = value_as_address (value); +@@ -1725,6 +1726,9 @@ cli-utils.o: $(srcdir)/cli/cli-utils.c + $(COMPILE) $(srcdir)/cli/cli-utils.c + $(POSTCOMPILE) -+#ifdef CRASH_MERGE -+ err = valprint_read_string (addr, *length, width, fetchlimit, -+#else - err = read_string (addr, *length, width, fetchlimit, -+#endif - byte_order, buffer, length); - if (err) - { ++crash.o: $(srcdir)/../../crash.c ++ $(COMPILE) $(srcdir)/../../crash.c ++ $(POSTCOMPILE) + + # + # GDBTK sub-directory --- gdb-7.6/readline/rltypedefs.h.orig +++ gdb-7.6/readline/rltypedefs.h @@ -31,10 +31,10 @@ extern "C" { @@ -1506,11 +1477,13 @@ CXXFLAGS = @CXXFLAGS@ --- gdb-7.6/gdb/defs.h.orig +++ gdb-7.6/gdb/defs.h -@@ -802,4 +802,8 @@ enum block_enum +@@ -802,4 +802,10 @@ enum block_enum #include "utils.h" +#ifdef CRASH_MERGE ++#define GDB_COMMON ++#include "../../defs.h" +extern int gdb_main_entry(int, char **); +extern void replace_ui_file_FILE(struct ui_file *, FILE *); +#endif @@ -1539,28 +1512,6 @@ #endif --- gdb-7.6/gdb/printcmd.c.orig +++ gdb-7.6/gdb/printcmd.c -@@ -573,11 +573,21 @@ print_address_symbolic (struct gdbarch * - int unmapped = 0; - int offset = 0; - int line = 0; -+#ifdef CRASH_MERGE -+ extern int gdb_print_callback(unsigned long); -+#endif - - /* Throw away both name and filename. */ - struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); - make_cleanup (free_current_contents, &filename); - -+#ifdef CRASH_MERGE -+ if (!gdb_print_callback(addr)) { -+ do_cleanups (cleanup_chain); -+ return 0; -+ } -+#endif -+ - if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset, - &filename, &line, &unmapped)) - { --- gdb-7.6/bfd/bfd-in.h.orig +++ gdb-7.6/bfd/bfd-in.h @@ -294,9 +294,6 @@ typedef struct bfd_section *sec_ptr; @@ -1651,33 +1602,6 @@ bfd_error_no_error = 0, --- gdb-7.6/gdb/symtab.c.orig +++ gdb-7.6/gdb/symtab.c -@@ -5405,7 +5405,7 @@ dump_enum(struct type *type, struct gnu_ - { - register int i; - int len; -- int lastval; -+ long long lastval; - - len = TYPE_NFIELDS (type); - lastval = 0; -@@ -5418,12 +5418,12 @@ dump_enum(struct type *type, struct gnu_ - for (i = 0; i < len; i++) { - fprintf_filtered(gdb_stdout, " %s", - TYPE_FIELD_NAME (type, i)); -- if (lastval != TYPE_FIELD_BITPOS (type, i)) { -- fprintf_filtered (gdb_stdout, " = %d", -- TYPE_FIELD_BITPOS (type, i)); -- lastval = TYPE_FIELD_BITPOS (type, i); -+ if (lastval != TYPE_FIELD_ENUMVAL (type, i)) { -+ fprintf_filtered (gdb_stdout, " = %s", -+ plongest(TYPE_FIELD_ENUMVAL (type, i))); -+ lastval = TYPE_FIELD_ENUMVAL (type, i); - } else -- fprintf_filtered(gdb_stdout, " = %d", lastval); -+ fprintf_filtered(gdb_stdout, " = %s", plongest(lastval)); - fprintf_filtered(gdb_stdout, "\n"); - lastval++; - } --- gdb-7.6/gdb/aarch64-linux-nat.c.orig +++ gdb-7.6/gdb/aarch64-linux-nat.c @@ -32,6 +32,7 @@ @@ -1688,3 +1612,26 @@ #include #include "gregset.h" +--- gdb-7.6/gdb/cli/cli-cmds.h.orig ++++ gdb-7.6/gdb/cli/cli-cmds.h +@@ -122,7 +122,8 @@ extern void source_script (char *, int); + /* Exported to objfiles.c. */ + + extern int find_and_open_script (const char *file, int search_path, +- FILE **streamp, char **full_path); ++ FILE **streamp, char **full_path, ++ int from_tty); + + /* Command tracing state. */ + +--- gdb-7.6/gdb/python/py-auto-load.c.orig ++++ gdb-7.6/gdb/python/py-auto-load.c +@@ -144,7 +144,7 @@ source_section_scripts (struct objfile * + } + + opened = find_and_open_script (file, 1 /*search_path*/, +- &stream, &full_path); ++ &stream, &full_path, 0); + + back_to = make_cleanup (null_cleanup, NULL); + if (opened) diff --git a/gdb-7.8.patch b/gdb-7.8.patch new file mode 100644 index 00000000..034ca786 --- /dev/null +++ b/gdb-7.8.patch @@ -0,0 +1,804 @@ +--- gdb-7.8.orig/libiberty/Makefile.in ++++ gdb-7.8/libiberty/Makefile.in +@@ -176,6 +176,7 @@ REQUIRED_OFILES = \ + ./getruntime.$(objext) ./hashtab.$(objext) ./hex.$(objext) \ + ./lbasename.$(objext) ./lrealpath.$(objext) \ + ./make-relative-prefix.$(objext) ./make-temp-file.$(objext) \ ++ ./mkstemps.$(objext) \ + ./objalloc.$(objext) \ + ./obstack.$(objext) \ + ./partition.$(objext) ./pexecute.$(objext) ./physmem.$(objext) \ +@@ -207,7 +208,7 @@ CONFIGURED_OFILES = ./asprintf.$(objext) + ./index.$(objext) ./insque.$(objext) \ + ./memchr.$(objext) ./memcmp.$(objext) ./memcpy.$(objext) \ + ./memmem.$(objext) ./memmove.$(objext) \ +- ./mempcpy.$(objext) ./memset.$(objext) ./mkstemps.$(objext) \ ++ ./mempcpy.$(objext) ./memset.$(objext) \ + ./pex-djgpp.$(objext) ./pex-msdos.$(objext) \ + ./pex-unix.$(objext) ./pex-win32.$(objext) \ + ./putenv.$(objext) \ +--- gdb-7.8.orig/sim/common/gentmap.c ++++ gdb-7.8/sim/common/gentmap.c +@@ -2,6 +2,7 @@ + + #include + #include ++#include + + struct tdefs { + char *symbol; +--- gdb-7.8.orig/opcodes/i386-dis.c ++++ gdb-7.8/opcodes/i386-dis.c +@@ -37,6 +37,8 @@ + #include "opintl.h" + #include "opcode/i386.h" + #include "libiberty.h" ++#define GDB_COMMON ++#include "../../defs.h" + + #include + +@@ -12588,6 +12590,9 @@ print_insn (bfd_vma pc, disassemble_info + dp = &dis386_twobyte[threebyte]; + need_modrm = twobyte_has_modrm[*codep]; + mandatory_prefix = twobyte_has_mandatory_prefix[*codep]; ++ if (dp->name && ((strcmp(dp->name, "ud2a") == 0) || (strcmp(dp->name, "ud2") == 0))) { ++ codep += kernel_BUG_encoding_bytes(); ++ } + codep++; + } + else +--- gdb-7.8.orig/gdb/dwarf2read.c ++++ gdb-7.8/gdb/dwarf2read.c +@@ -3017,7 +3017,11 @@ read_index_from_section (struct objfile + indices. */ + if (version < 4) + { ++#ifdef CRASH_MERGE ++ static int warning_printed = 1; ++#else + static int warning_printed = 0; ++#endif + if (!warning_printed) + { + warning (_("Skipping obsolete .gdb_index section in %s."), +@@ -3036,7 +3040,11 @@ read_index_from_section (struct objfile + "set use-deprecated-index-sections on". */ + if (version < 6 && !deprecated_ok) + { ++#ifdef CRASH_MERGE ++ static int warning_printed = 1; ++#else + static int warning_printed = 0; ++#endif + if (!warning_printed) + { + warning (_("\ +--- gdb-7.8.orig/gdb/amd64-linux-nat.c ++++ gdb-7.8/gdb/amd64-linux-nat.c +@@ -45,6 +45,17 @@ + /* ezannoni-2003-07-09: I think this is fixed. The extraneous defs have + been removed from ptrace.h in the kernel. However, better safe than + sorry. */ ++#ifdef CRASH_MERGE ++/* ++ * When compiling within a 2.6.25-based Fedora build environment with ++ * gcc 4.3, four new "typedef unsigned int u32;" declarations were ++ * required due to a new ptrace_bts_config structure declaration in ++ * "asm-x86/ptrace-abi.h" that used u32 members, but u32 is defined in ++ * "asm-x86/types.h" within a __KERNEL__ section. They've been changed ++ * to __u32, but this patch remains for building in that environment. ++ */ ++typedef unsigned int u32; ++#endif + #include + #include + #include "gdb_proc_service.h" +--- gdb-7.8.orig/gdb/symfile.c ++++ gdb-7.8/gdb/symfile.c +@@ -745,7 +745,26 @@ default_symfile_offsets (struct objfile + for (cur_sec = abfd->sections; cur_sec != NULL; cur_sec = cur_sec->next) + /* We do not expect this to happen; just skip this step if the + relocatable file has a section with an assigned VMA. */ +- if (bfd_section_vma (abfd, cur_sec) != 0) ++ if (bfd_section_vma (abfd, cur_sec) != 0 ++ /* ++ * Kernel modules may have some non-zero VMAs, i.e., like the ++ * __ksymtab and __ksymtab_gpl sections in this example: ++ * ++ * Section Headers: ++ * [Nr] Name Type Address Offset ++ * Size EntSize Flags Link Info Align ++ * ... ++ * [ 8] __ksymtab PROGBITS 0000000000000060 0000ad90 ++ * 0000000000000010 0000000000000000 A 0 0 16 ++ * [ 9] .rela__ksymtab RELA 0000000000000000 0000ada0 ++ * 0000000000000030 0000000000000018 43 8 8 ++ * [10] __ksymtab_gpl PROGBITS 0000000000000070 0000add0 ++ * 00000000000001a0 0000000000000000 A 0 0 16 ++ * ... ++ * ++ * but they should be treated as if they are NULL. ++ */ ++ && strncmp (bfd_get_section_name (abfd, cur_sec), "__k", 3) != 0) + break; + + if (cur_sec == NULL) +@@ -1495,6 +1514,15 @@ find_separate_debug_file (const char *di + if (separate_debug_file_exists (debugfile, crc32, objfile)) + return debugfile; + ++#ifdef CRASH_MERGE ++{ ++ if (check_specified_module_tree(objfile_name(objfile), debugfile) && ++ separate_debug_file_exists(debugfile, crc32, objfile)) { ++ return debugfile; ++ } ++} ++#endif ++ + /* Then try in the global debugfile directories. + + Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will +@@ -1571,6 +1599,9 @@ find_separate_debug_file_by_debuglink (s + char *debugfile; + unsigned long crc32; + struct cleanup *cleanups; ++#ifdef CRASH_MERGE ++ char *name_copy; ++#endif + + debuglink = bfd_get_debug_link_info (objfile->obfd, &crc32); + +@@ -1624,6 +1655,12 @@ find_separate_debug_file_by_debuglink (s + } + + do_cleanups (cleanups); ++#ifdef CRASH_MERGE ++ if (debugfile == NULL) { ++ name_copy = check_specified_kernel_debug_file(); ++ return (name_copy ? xstrdup(name_copy) : NULL); ++ } ++#endif + return debugfile; + } + +@@ -2395,8 +2432,10 @@ add_symbol_file_command (char *args, int + } + section_addrs->num_sections = sec_num; + ++#ifndef CRASH_MERGE + if (from_tty && (!query ("%s", ""))) + error (_("Not confirmed.")); ++#endif + + objf = symbol_file_add (filename, from_tty ? SYMFILE_VERBOSE : 0, + section_addrs, flags); +@@ -3762,6 +3801,15 @@ bfd_byte * + symfile_relocate_debug_section (struct objfile *objfile, + asection *sectp, bfd_byte *buf) + { ++#ifdef CRASH_MERGE ++ /* Executable files have all the relocations already resolved. ++ * Handle files linked with --emit-relocs. ++ * http://sources.redhat.com/ml/gdb/2006-08/msg00137.html ++ */ ++ bfd *abfd = objfile->obfd; ++ if ((abfd->flags & EXEC_P) != 0) ++ return NULL; ++#endif + gdb_assert (objfile->sf->sym_relocate); + + return (*objfile->sf->sym_relocate) (objfile, sectp, buf); +--- gdb-7.8.orig/gdb/cli/cli-cmds.c ++++ gdb-7.8/gdb/cli/cli-cmds.c +@@ -474,7 +474,7 @@ show_script_ext_mode (struct ui_file *fi + + int + find_and_open_script (const char *script_file, int search_path, +- FILE **streamp, char **full_pathp) ++ FILE **streamp, char **full_pathp, int from_tty) + { + char *file; + int fd; +@@ -514,6 +514,31 @@ find_and_open_script (const char *script + return 0; + } + ++#ifdef CRASH_MERGE ++ /* ++ * Only allow trusted versions of .gdbinit files to be ++ * sourced during session initialization. ++ */ ++ if (from_tty == -1) ++ { ++ struct stat statbuf; ++ FILE *stream = *streamp; ++ int fd = fileno (stream); ++ if (fstat (fd, &statbuf) < 0) ++ { ++ perror_with_name (*full_pathp); ++ fclose (stream); ++ return 0; ++ } ++ if (statbuf.st_uid != getuid () || (statbuf.st_mode & S_IWOTH)) ++ { ++ untrusted_file(NULL, *full_pathp); ++ fclose (stream); ++ return 0; ++ } ++ } ++#endif ++ + return 1; + } + +@@ -566,13 +591,18 @@ source_script_with_search (const char *f + if (file == NULL || *file == 0) + error (_("source command requires file name of file to source.")); + +- if (!find_and_open_script (file, search_path, &stream, &full_path)) ++ if (!find_and_open_script (file, search_path, &stream, &full_path, ++ from_tty)) + { + /* The script wasn't found, or was otherwise inaccessible. + If the source command was invoked interactively, throw an + error. Otherwise (e.g. if it was invoked by a script), + just emit a warning, rather than cause an error. */ ++#ifdef CRASH_MERGE ++ if (from_tty > 0) ++#else + if (from_tty) ++#endif + perror_with_name (file); + else + { +--- gdb-7.8.orig/gdb/cli/cli-interp.c ++++ gdb-7.8/gdb/cli/cli-interp.c +@@ -229,4 +229,5 @@ _initialize_cli_interp (void) + cli_interp = interp_new (INTERP_CONSOLE, &procs); + + interp_add (cli_interp); ++ cli_procs = &procs; + } +--- gdb-7.8.orig/gdb/psymtab.c ++++ gdb-7.8/gdb/psymtab.c +@@ -312,6 +312,7 @@ find_pc_sect_psymtab (struct objfile *ob + /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity + than the later used TEXTLOW/TEXTHIGH one. */ + ++#ifndef __i386__ + if (objfile->psymtabs_addrmap != NULL) + { + pst = addrmap_find (objfile->psymtabs_addrmap, pc); +@@ -346,6 +347,7 @@ find_pc_sect_psymtab (struct objfile *ob + } + + next: ++#endif + + /* Existing PSYMTABS_ADDRMAP mapping is present even for PARTIAL_SYMTABs + which still have no corresponding full SYMTABs read. But it is not +@@ -364,7 +366,12 @@ find_pc_sect_psymtab (struct objfile *ob + + best_pst = find_pc_sect_psymtab_closer (objfile, pc, section, pst, + msymbol); ++#ifdef CRASH_MERGE ++ if ((best_pst != NULL) && ++ gdb_line_number_callback(pc, pst->textlow, pst->texthigh)) ++#else + if (best_pst != NULL) ++#endif + return best_pst; + } + +--- gdb-7.8.orig/gdb/symtab.c ++++ gdb-7.8/gdb/symtab.c +@@ -1335,6 +1335,11 @@ lookup_symbol_in_language (const char *n + is_a_field_of_this); + do_cleanups (cleanup); + ++#ifdef CRASH_MERGE ++ if (returnval && (domain == VAR_DOMAIN)) ++ gdb_bait_and_switch((char *)modified_name, returnval); ++#endif ++ + return returnval; + } + +@@ -1346,6 +1351,10 @@ lookup_symbol (const char *name, const s + domain_enum domain, + struct field_of_this_result *is_a_field_of_this) + { ++#ifdef CRASH_MERGE ++ if (!block) ++ block = gdb_get_crash_block(); ++#endif + return lookup_symbol_in_language (name, block, domain, + current_language->la_language, + is_a_field_of_this); +--- gdb-7.8.orig/gdb/c-typeprint.c ++++ gdb-7.8/gdb/c-typeprint.c +@@ -1101,7 +1101,8 @@ c_type_print_base (struct type *type, st + fprintf_filtered (stream, "static "); + c_print_type (TYPE_FIELD_TYPE (type, i), + TYPE_FIELD_NAME (type, i), +- stream, show - 1, level + 4, ++ stream, strlen(TYPE_FIELD_NAME (type, i)) ? ++ show - 1 : show, level + 4, + &local_flags); + if (!field_is_static (&TYPE_FIELD (type, i)) + && TYPE_FIELD_PACKED (type, i)) +--- gdb-7.8.orig/gdb/xml-syscall.c ++++ gdb-7.8/gdb/xml-syscall.c +@@ -38,7 +38,11 @@ + static void + syscall_warn_user (void) + { ++#ifdef CRASH_MERGE ++ static int have_warned = 1; ++#else + static int have_warned = 0; ++#endif + if (!have_warned) + { + have_warned = 1; +--- gdb-7.8.orig/gdb/exceptions.c ++++ gdb-7.8/gdb/exceptions.c +@@ -218,6 +218,10 @@ exceptions_state_mc_action_iter_1 (void) + + /* Return EXCEPTION to the nearest containing catch_errors(). */ + ++#ifdef CRASH_MERGE ++void (*error_hook) (void) ATTRIBUTE_NORETURN; ++#endif ++ + void + throw_exception (struct gdb_exception exception) + { +@@ -225,6 +229,13 @@ throw_exception (struct gdb_exception ex + immediate_quit = 0; + + do_cleanups (all_cleanups ()); ++#ifdef CRASH_MERGE ++ if (error_hook) { ++ fprintf_filtered(gdb_stderr, "%s\n", exception.message); ++ (*error_hook)(); ++ } else ++ fprintf_filtered(gdb_stderr, "gdb called without error_hook: %s\n", exception.message); ++#endif + + /* Jump to the containing catch_errors() call, communicating REASON + to that call via setjmp's return value. Note that REASON can't +--- gdb-7.8.orig/gdb/target.c ++++ gdb-7.8/gdb/target.c +@@ -1294,6 +1294,12 @@ target_xfer_partial (struct target_ops * + int + target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len) + { ++#ifdef CRASH_MERGE ++ if (gdb_readmem_callback(memaddr, (void *)myaddr, len, 0)) ++ return 0; ++ else ++ return EIO; ++#endif + /* Dispatch to the topmost target, not the flattened current_target. + Memory accesses check target->to_has_(all_)memory, and the + flattened target doesn't inherit those. */ +@@ -1359,6 +1365,12 @@ target_read_code (CORE_ADDR memaddr, gdb + int + target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len) + { ++#ifdef CRASH_MERGE ++ if (gdb_readmem_callback(memaddr, (void *)myaddr, len, 1)) ++ return 0; ++ else ++ return EIO; ++#endif + /* See comment in target_read_memory about why the request starts at + current_target.beneath. */ + if (target_write (current_target.beneath, TARGET_OBJECT_MEMORY, NULL, +--- gdb-7.8.orig/gdb/printcmd.c ++++ gdb-7.8/gdb/printcmd.c +@@ -581,6 +581,13 @@ print_address_symbolic (struct gdbarch * + struct cleanup *cleanup_chain = make_cleanup (free_current_contents, &name); + make_cleanup (free_current_contents, &filename); + ++#ifdef CRASH_MERGE ++ if (!gdb_print_callback(addr)) { ++ do_cleanups (cleanup_chain); ++ return 0; ++ } ++#endif ++ + if (build_address_symbolic (gdbarch, addr, do_demangle, &name, &offset, + &filename, &line, &unmapped)) + { +@@ -1004,11 +1011,62 @@ print_command_1 (const char *exp, int vo + } + + static void ++print_command_2 (char *exp, int inspect, int voidprint) ++{ ++ struct expression *expr; ++ struct cleanup *old_chain = 0; ++ char format = 0; ++ struct value *val; ++ struct format_data fmt; ++ int cleanup = 0; ++ ++ if (exp && *exp == '/') ++ { ++ exp++; ++ fmt = decode_format (&exp, last_format, 0); ++ validate_format (fmt, "print"); ++ last_format = format = fmt.format; ++ } ++ else ++ { ++ fmt.count = 1; ++ fmt.format = 0; ++ fmt.size = 0; ++ fmt.raw = 0; ++ } ++ ++ if (exp && *exp) ++ { ++ expr = parse_expression (exp); ++ old_chain = make_cleanup (free_current_contents, &expr); ++ cleanup = 1; ++ val = evaluate_expression (expr); ++ } ++ else ++ val = access_value_history (0); ++ ++ printf_filtered ("%d %d %d %d %d %d\n", ++ TYPE_CODE (check_typedef(value_type (val))), ++ TYPE_UNSIGNED (check_typedef(value_type (val))), ++ TYPE_LENGTH (check_typedef(value_type(val))), ++ value_offset (val), value_bitpos (val), value_bitsize(val)); ++ ++ if (cleanup) ++ do_cleanups (old_chain); ++} ++ ++static void + print_command (char *exp, int from_tty) + { + print_command_1 (exp, 1); + } + ++static void ++printm_command (char *exp, int from_tty) ++{ ++ print_command_2 (exp, 0, 1); ++} ++ + /* Same as print, except it doesn't print void results. */ + static void + call_command (char *exp, int from_tty) +@@ -2618,6 +2676,12 @@ EXP may be preceded with /FMT, where FMT + but no count or size letter (see \"x\" command).")); + set_cmd_completer (c, expression_completer); + add_com_alias ("p", "print", class_vars, 1); ++ ++ c = add_com ("printm", class_vars, printm_command, _("\ ++Similar to \"print\" command, but it used to print the type, size, offset,\n\ ++bitpos and bitsize of the expression EXP.")); ++ set_cmd_completer (c, expression_completer); ++ + add_com_alias ("inspect", "print", class_vars, 1); + + add_setshow_uinteger_cmd ("max-symbolic-offset", no_class, +--- gdb-7.8.orig/gdb/ui-file.c ++++ gdb-7.8/gdb/ui-file.c +@@ -726,6 +726,17 @@ gdb_fopen (const char *name, const char + return stdio_file_new (f, 1); + } + ++#ifdef CRASH_MERGE ++void ++replace_ui_file_FILE(struct ui_file *file, FILE *fp) ++{ ++ struct stdio_file *stdio_file; ++ ++ stdio_file = (struct stdio_file *)ui_file_data(file); ++ stdio_file->file = fp; ++} ++#endif ++ + /* ``struct ui_file'' implementation that maps onto two ui-file objects. */ + + static ui_file_write_ftype tee_file_write; +--- gdb-7.8.orig/gdb/main.c ++++ gdb-7.8/gdb/main.c +@@ -914,7 +914,7 @@ captured_main (void *data) + { + print_gdb_version (gdb_stdout); + wrap_here (""); +- printf_filtered ("\n"); ++ printf_filtered ("\n\n"); + exit (0); + } + +@@ -994,8 +994,13 @@ captured_main (void *data) + processed; it sets global parameters, which are independent of + what file you are debugging or what directory you are in. */ + if (system_gdbinit && !inhibit_gdbinit) ++#ifdef CRASH_MERGE ++ catch_command_errors_const (source_script, system_gdbinit, ++ -1, RETURN_MASK_ALL); ++#else + catch_command_errors_const (source_script, system_gdbinit, + 0, RETURN_MASK_ALL); ++#endif + + /* Read and execute $HOME/.gdbinit file, if it exists. This is done + *before* all the command line arguments are processed; it sets +@@ -1003,8 +1008,13 @@ captured_main (void *data) + debugging or what directory you are in. */ + + if (home_gdbinit && !inhibit_gdbinit && !inhibit_home_gdbinit) ++#ifdef CRASH_MERGE ++ catch_command_errors_const (source_script, ++ home_gdbinit, -1, RETURN_MASK_ALL); ++#else + catch_command_errors_const (source_script, + home_gdbinit, 0, RETURN_MASK_ALL); ++#endif + + /* Process '-ix' and '-iex' options early. */ + for (i = 0; VEC_iterate (cmdarg_s, cmdarg_vec, i, cmdarg_p); i++) +@@ -1045,8 +1055,13 @@ captured_main (void *data) + catch_command_errors returns non-zero on success! */ + if (catch_command_errors (exec_file_attach, execarg, + !batch_flag, RETURN_MASK_ALL)) ++#ifdef CRASH_MERGE ++ catch_command_errors_const (symbol_file_add_main, symarg, ++ 0, RETURN_MASK_ALL); ++#else + catch_command_errors_const (symbol_file_add_main, symarg, + !batch_flag, RETURN_MASK_ALL); ++#endif + } + else + { +@@ -1106,8 +1121,13 @@ captured_main (void *data) + { + auto_load_local_gdbinit_loaded = 1; + ++#ifdef CRASH_MERGE ++ catch_command_errors_const (source_script, local_gdbinit, ++ -1, RETURN_MASK_ALL); ++#else + catch_command_errors_const (source_script, local_gdbinit, 0, + RETURN_MASK_ALL); ++#endif + } + } + +@@ -1153,6 +1173,12 @@ captured_main (void *data) + while (1) + { + catch_errors (captured_command_loop, 0, "", RETURN_MASK_ALL); ++#ifdef CRASH_MERGE ++ { ++ int console(char *, ...); ++ console("\n"); ++ } ++#endif + } + /* No exit -- exit is through quit_command. */ + } +@@ -1166,6 +1192,22 @@ gdb_main (struct captured_main_args *arg + return 1; + } + ++#ifdef CRASH_MERGE ++/* ++ * NOTE: adapted from gdb.c, which is no longer built in; changed name of ++ * original main() to gdb_main_entry() for use as crash entry point ++ */ ++int ++gdb_main_entry (int argc, char **argv) ++{ ++ struct captured_main_args args; ++ memset (&args, 0, sizeof args); ++ args.argc = argc; ++ args.argv = argv; ++ args.interpreter_p = "crash-command"; ++ return gdb_main (&args); ++} ++#endif + + /* Don't use *_filtered for printing help. We don't want to prompt + for continue no matter how small the screen or how much we're going +--- gdb-7.8.orig/gdb/Makefile.in ++++ gdb-7.8/gdb/Makefile.in +@@ -483,8 +483,8 @@ SUBDIR_GDBTK_DEPS = $(LIBGUI) $(TCL_DEPS + SUBDIR_GDBTK_LDFLAGS= + SUBDIR_GDBTK_CFLAGS= -DGDBTK + +-CONFIG_OBS= @CONFIG_OBS@ +-CONFIG_SRCS= @CONFIG_SRCS@ ++CONFIG_OBS= @CONFIG_OBS@ crash.o ++CONFIG_SRCS= @CONFIG_SRCS@ ../../crash.c + CONFIG_DEPS= @CONFIG_DEPS@ + CONFIG_LDFLAGS = @CONFIG_LDFLAGS@ + ENABLE_CFLAGS= @ENABLE_CFLAGS@ +@@ -501,7 +501,7 @@ HAVE_NATIVE_GCORE_TARGET = @HAVE_NATIVE_ + # It is also possible that you will need to add -I/usr/include/sys if + # your system doesn't have fcntl.h in /usr/include (which is where it + # should be according to Posix). +-DEFS = @DEFS@ ++DEFS = -DCRASH_MERGE -DGDB_7_8 @DEFS@ + GDB_CFLAGS = -I. -I$(srcdir) -I$(srcdir)/common -I$(srcdir)/config \ + -DLOCALEDIR="\"$(localedir)\"" $(DEFS) + +@@ -931,7 +931,7 @@ common/linux-osdata.h gdb-dlfcn.h auto-l + gdb_bfd.h sparc-ravenscar-thread.h ppc-ravenscar-thread.h common/linux-btrace.h \ + ctf.h common/i386-cpuid.h common/i386-gcc-cpuid.h target/resume.h \ + target/wait.h target/waitstatus.h nat/linux-nat.h nat/linux-waitpid.h \ +-common/print-utils.h common/rsp-low.h ++common/print-utils.h common/rsp-low.h crash.h + + # Header files that already have srcdir in them, or which are in objdir. + +@@ -1034,7 +1034,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $ + + TSOBS = inflow.o + +-SUBDIRS = doc @subdirs@ data-directory $(GNULIB_BUILDDIR) ++SUBDIRS = build_no_subdirs + CLEANDIRS = $(SUBDIRS) + + # List of subdirectories in the build tree that must exist. +@@ -1069,8 +1069,8 @@ generated_files = config.h observer.h ob + $(COMPILE) $< + $(POSTCOMPILE) + +-all: gdb$(EXEEXT) $(CONFIG_ALL) +- @$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do ++all: gdb$(EXEEXT) ++ @$(MAKE) -s $(FLAGS_TO_PASS) DO=all "DODIRS=`echo $(SUBDIRS) | sed 's/testsuite//'`" subdir_do + + installcheck: + +@@ -1326,15 +1326,16 @@ libgdb.a: $(LIBGDB_OBS) + + # Removing the old gdb first works better if it is running, at least on SunOS. + gdb$(EXEEXT): gdb.o $(LIBGDB_OBS) $(ADD_DEPS) $(CDEPS) $(TDEPLIBS) +- rm -f gdb$(EXEEXT) ++ @rm -f gdb$(EXEEXT) ++ @(cd ../..; make --no-print-directory GDB_FLAGS=-DGDB_7_8 library) + $(CC_LD) $(INTERNAL_LDFLAGS) $(WIN32LDAPP) \ +- -o gdb$(EXEEXT) gdb.o $(LIBGDB_OBS) \ +- $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) ++ -o $(shell /bin/cat mergeobj) $(LIBGDB_OBS) \ ++ $(TDEPLIBS) $(TUI_LIBRARY) $(CLIBS) $(LOADLIBES) $(shell /bin/cat mergelibs) + + # Convenience rule to handle recursion. + $(LIBGNU) $(GNULIB_H): all-lib + all-lib: $(GNULIB_BUILDDIR)/Makefile +- @$(MAKE) $(FLAGS_TO_PASS) DO=all DODIRS=$(GNULIB_BUILDDIR) subdir_do ++ @$(MAKE) $(FLAGS_TO_PASS) DO=all DODIRS=$(GNULIB_BUILDDIR) subdir_do -s + .PHONY: all-lib + + # Convenience rule to handle recursion. +@@ -1898,6 +1899,9 @@ cli-utils.o: $(srcdir)/cli/cli-utils.c + $(COMPILE) $(srcdir)/cli/cli-utils.c + $(POSTCOMPILE) + ++crash.o: $(srcdir)/../../crash.c ++ $(COMPILE) $(srcdir)/../../crash.c ++ $(POSTCOMPILE) + + # + # GDBTK sub-directory +--- gdb-7.8.orig/readline/rltypedefs.h ++++ gdb-7.8/readline/rltypedefs.h +@@ -31,10 +31,10 @@ extern "C" { + #if !defined (_FUNCTION_DEF) + # define _FUNCTION_DEF + +-typedef int Function (); +-typedef void VFunction (); +-typedef char *CPFunction (); +-typedef char **CPPFunction (); ++typedef int Function (void); ++typedef void VFunction (void); ++typedef char *CPFunction (void); ++typedef char **CPPFunction (void); + + #endif /* _FUNCTION_DEF */ + +--- gdb-7.8.orig/readline/readline.h ++++ gdb-7.8/readline/readline.h +@@ -378,7 +378,7 @@ extern int rl_crlf PARAMS((void)); + #if defined (USE_VARARGS) && defined (PREFER_STDARG) + extern int rl_message (const char *, ...) __attribute__((__format__ (printf, 1, 2))); + #else +-extern int rl_message (); ++extern int rl_message (void); + #endif + + extern int rl_show_char PARAMS((int)); +--- gdb-7.8.orig/readline/misc.c ++++ gdb-7.8/readline/misc.c +@@ -405,7 +405,7 @@ _rl_history_set_point () + + #if defined (VI_MODE) + if (rl_editing_mode == vi_mode && _rl_keymap != vi_insertion_keymap) +- rl_point = 0; ++ rl_point = rl_end; + #endif /* VI_MODE */ + + if (rl_editing_mode == emacs_mode) +--- gdb-7.8.orig/Makefile.in ++++ gdb-7.8/Makefile.in +@@ -342,6 +342,9 @@ AR_FOR_BUILD = @AR_FOR_BUILD@ + AS_FOR_BUILD = @AS_FOR_BUILD@ + CC_FOR_BUILD = @CC_FOR_BUILD@ + CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@ ++ifeq (${CRASH_TARGET}, PPC64) ++CFLAGS_FOR_BUILD += -m64 -fPIC ++endif + CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@ + CXX_FOR_BUILD = @CXX_FOR_BUILD@ + DLLTOOL_FOR_BUILD = @DLLTOOL_FOR_BUILD@ +@@ -407,6 +410,9 @@ GNATBIND = @GNATBIND@ + GNATMAKE = @GNATMAKE@ + + CFLAGS = @CFLAGS@ ++ifeq (${CRASH_TARGET}, PPC64) ++CFLAGS += -m64 -fPIC ++endif + LDFLAGS = @LDFLAGS@ + LIBCFLAGS = $(CFLAGS) + CXXFLAGS = @CXXFLAGS@ +--- gdb-7.8.orig/gdb/defs.h ++++ gdb-7.8/gdb/defs.h +@@ -756,4 +756,9 @@ enum block_enum + + #include "utils.h" + ++#ifdef CRASH_MERGE ++#define GDB_COMMON ++#include "../../defs.h" ++#include "../../crash.h" ++#endif + #endif /* #ifndef DEFS_H */ +--- gdb-7.8.orig/gdb/s390-linux-nat.c ++++ gdb-7.8/gdb/s390-linux-nat.c +@@ -37,6 +37,8 @@ + #include + #include + ++#include ++ + #ifndef PTRACE_GETREGSET + #define PTRACE_GETREGSET 0x4204 + #endif +--- gdb-7.8.orig/gdb/cli/cli-cmds.h ++++ gdb-7.8/gdb/cli/cli-cmds.h +@@ -118,7 +118,8 @@ extern void source_script (const char *, + /* Exported to objfiles.c. */ + + extern int find_and_open_script (const char *file, int search_path, +- FILE **streamp, char **full_path); ++ FILE **streamp, char **full_path, ++ int from_tty); + + /* Command tracing state. */ + +--- gdb-7.8.orig/gdb/auto-load.c ++++ gdb-7.8/gdb/auto-load.c +@@ -949,7 +949,7 @@ source_section_scripts (struct objfile * + } + + opened = find_and_open_script (file, 1 /*search_path*/, +- &stream, &full_path); ++ &stream, &full_path, 0); + + back_to = make_cleanup (null_cleanup, NULL); + if (opened) diff --git a/gdb_interface.c b/gdb_interface.c index 97a1f27e..56ac280b 100644 --- a/gdb_interface.c +++ b/gdb_interface.c @@ -17,15 +17,15 @@ #include "defs.h" -static void exit_after_gdb_info(void); +static void exit_after_gdb_info(void *ignore); static int is_restricted_command(char *, ulong); static void strip_redirection(char *); int get_frame_offset(ulong); int *gdb_output_format; unsigned int *gdb_print_max; -int *gdb_prettyprint_structs; -int *gdb_prettyprint_arrays; +int *gdb_prettyformat_structs; +int *gdb_prettyformat_arrays; int *gdb_repeat_count_threshold; int *gdb_stop_print_at_null; unsigned int *gdb_output_radix; @@ -68,31 +68,9 @@ gdb_main_loop(int argc, char **argv) } optind = 0; -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) - command_loop_hook = main_loop; -#else - deprecated_command_loop_hook = main_loop; -#endif gdb_main_entry(argc, argv); } -/* - * Update any hooks that gdb has set. - */ -void -update_gdb_hooks(void) -{ -#if defined(GDB_6_0) || defined(GDB_6_1) - command_loop_hook = pc->flags & VERSION_QUERY ? - exit_after_gdb_info : main_loop; - target_new_objfile_hook = NULL; -#endif -#if defined(GDB_7_0) || defined(GDB_7_3_1) || defined(GDB_7_6) - deprecated_command_loop_hook = pc->flags & VERSION_QUERY ? - exit_after_gdb_info : main_loop; -#endif -} - void gdb_readnow_warning(void) { @@ -110,30 +88,17 @@ gdb_readnow_warning(void) /* * Used only by the -v command line option, get gdb to initialize itself - * with no arguments, print its version and GPL paragraph, and then call - * back to exit_after_gdb_info(). + * with no arguments, print its version and GPL paragraph, and then exit out. */ void display_gdb_banner(void) { optind = 0; -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) - command_loop_hook = exit_after_gdb_info; -#else - deprecated_command_loop_hook = exit_after_gdb_info; -#endif args[0] = "gdb"; args[1] = "-version"; gdb_main_entry(2, args); } -static void -exit_after_gdb_info(void) -{ - fprintf(fp, "\n"); - clean_exit(0); -} - /* * Stash a copy of the gdb version locally. This can be called before * gdb gets initialized, so bypass gdb_interface(). @@ -173,30 +138,33 @@ gdb_session_init(void) /* * Set up pointers to gdb variables. */ -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) - gdb_output_format = &output_format; - gdb_print_max = &print_max; - gdb_prettyprint_structs = &prettyprint_structs; - gdb_prettyprint_arrays = &prettyprint_arrays; - gdb_repeat_count_threshold = &repeat_count_threshold; - gdb_stop_print_at_null = &stop_print_at_null; - gdb_output_radix = &output_radix; -#else gdb_output_format = (int *) gdb_user_print_option_address("output_format"); gdb_print_max = (unsigned int *) gdb_user_print_option_address("print_max"); - gdb_prettyprint_structs = (int *) - gdb_user_print_option_address("prettyprint_structs"); - gdb_prettyprint_arrays = (int *) - gdb_user_print_option_address("prettyprint_arrays"); + + /* gdb 7.7 renamed prettyprint to prettyformat */ + gdb_prettyformat_structs = (int *) + gdb_user_print_option_address("prettyformat_structs"); + if (!gdb_prettyformat_structs) { + gdb_prettyformat_structs = (int *) + gdb_user_print_option_address("prettyprint_structs"); + } + + gdb_prettyformat_arrays = (int *) + gdb_user_print_option_address("prettyformat_arrays"); + if (!gdb_prettyformat_arrays) { + gdb_prettyformat_arrays = (int *) + gdb_user_print_option_address("prettyprint_arrays"); + } + gdb_repeat_count_threshold = (int *) gdb_user_print_option_address("repeat_count_threshold"); gdb_stop_print_at_null = (int *) gdb_user_print_option_address("stop_print_at_null"); gdb_output_radix = (unsigned int *) gdb_user_print_option_address("output_radix"); -#endif + /* * If the output radix is set via the --hex or --dec command line * option, then pc->output_radix will be non-zero; otherwise use @@ -218,12 +186,9 @@ gdb_session_init(void) *gdb_output_format = 0; } - *gdb_prettyprint_structs = 1; + *gdb_prettyformat_structs = 1; *gdb_repeat_count_threshold = 0x7fffffff; *gdb_print_max = 256; -#ifdef GDB_5_3 - gdb_disassemble_from_exec = 0; -#endif pc->flags |= GDB_INIT; /* set here so gdb_interface will work */ @@ -415,8 +380,8 @@ gdb_interface(struct gnu_request *req) void dump_gdb_data(void) { - fprintf(fp, " prettyprint_arrays: %d\n", *gdb_prettyprint_arrays); - fprintf(fp, " prettyprint_structs: %d\n", *gdb_prettyprint_structs); + fprintf(fp, " prettyformat_arrays: %d\n", *gdb_prettyformat_arrays); + fprintf(fp, " prettyformat_structs: %d\n", *gdb_prettyformat_structs); fprintf(fp, "repeat_count_threshold: %x\n", *gdb_repeat_count_threshold); fprintf(fp, " stop_print_at_null: %d\n", *gdb_stop_print_at_null); fprintf(fp, " print_max: %d\n", *gdb_print_max); @@ -499,11 +464,7 @@ dump_gnu_request(struct gnu_request *req, int in_gdb) console("name: %lx ", (ulong)req->name); console("length: %ld ", req->length); console("typecode: %d\n", req->typecode); -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) || defined(GDB_7_0) - console("typename: %s\n", req->typename); -#else console("type_name: %s\n", req->type_name); -#endif console("target_typename: %s\n", req->target_typename); console("target_length: %ld ", req->target_length); console("target_typecode: %d ", req->target_typecode); @@ -617,7 +578,7 @@ restore_gdb_sanity(void) *gdb_output_format = (*gdb_output_radix == 10) ? 0 : 'x'; } - *gdb_prettyprint_structs = 1; /* these may piss somebody off... */ + *gdb_prettyformat_structs = 1; /* these may piss somebody off... */ *gdb_repeat_count_threshold = 0x7fffffff; error_hook = NULL; @@ -931,11 +892,7 @@ gdb_error_hook(void) gdb_command_string(pc->cur_gdb_cmd, buf1, TRUE), buf2); } -#ifdef GDB_7_6 do_cleanups(all_cleanups()); -#else - do_cleanups(NULL); -#endif longjmp(pc->gdb_interface_env, 1); } diff --git a/help.c b/help.c index 723e79e5..d762a933 100644 --- a/help.c +++ b/help.c @@ -36,11 +36,7 @@ static void dump_registers(void); #define GPLv2 2 #define GPLv3 3 -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) -static int GPL_version = GPLv2; -#else static int GPL_version = GPLv3; -#endif static char *program_usage_info[] = { @@ -1742,11 +1738,7 @@ char *help_bt[] = { " -c cpu display the stack trace of the active task on one or more CPUs,", " which can be specified using the format \"3\", \"1,8,9\", \"1-23\",", " or \"1,8,9-14\". (only applicable to crash dumps)", -#ifdef GDB_5_3 -" -g use gdb stack trace code. (alpha only)", -#else " -g displays the stack traces of all threads in the thread group of", -#endif " the target task; the thread group leader will be displayed first.", " -r display raw stack data, consisting of a memory dump of the two", " pages of memory containing the task_union structure.", diff --git a/kernel.c b/kernel.c index 3144fe8b..204c7ac8 100644 --- a/kernel.c +++ b/kernel.c @@ -936,7 +936,7 @@ verify_version(void) if (!accessible(linux_banner)) goto bad_match; - if (!read_string(linux_banner, buf, BUFSIZE-1)) + if (!mem_read_string(linux_banner, buf, BUFSIZE-1)) error(WARNING, "cannot read linux_banner string\n"); if (ACTIVE()) { @@ -1797,7 +1797,7 @@ BUG_x86(void) return 0; } - if (!read_string(fileptr, buf1, BUFSIZE-1)) + if (!mem_read_string(fileptr, buf1, BUFSIZE-1)) error(WARNING, "cannot read BUG (ud2a) encoded filename address: %lx\n", fileptr); @@ -2073,11 +2073,7 @@ cmd_bt(void) break; case 'g': -#ifdef GDB_5_3 - bt->flags |= BT_USE_GDB; -#else bt->flags |= BT_THREAD_GROUP; -#endif break; case 'x': @@ -3237,7 +3233,7 @@ verify_modules(void) OFFSET(module_name)); mod_size = LONG(modbuf + OFFSET(module_size)); - if (!read_string(mod_name, buf, + if (!mem_read_string(mod_name, buf, BUFSIZE-1) || !STREQ(lm->mod_name, buf) || (mod_size != lm->mod_size)){ irregularities++; @@ -3545,7 +3541,7 @@ cmd_mod(void) } int -check_specified_module_tree(char *module, char *gdb_buffer) +check_specified_module_tree(const char *module, char *gdb_buffer) { char *p1, *treebuf; int retval; @@ -5881,7 +5877,7 @@ generic_dump_irq(int irq) fprintf(fp, " typename: %lx ", tmp1); BZERO(buf, BUFSIZE); - if (read_string(tmp1, buf, BUFSIZE-1)) + if (mem_read_string(tmp1, buf, BUFSIZE-1)) fprintf(fp, "\"%s\"", buf); fprintf(fp, "\n"); @@ -6222,7 +6218,7 @@ generic_dump_irq(int irq) "irqaction name", FAULT_ON_ERROR); fprintf(fp, " name: %lx ", tmp1); BZERO(buf, BUFSIZE); - if (read_string(tmp1, buf, BUFSIZE-1)) + if (mem_read_string(tmp1, buf, BUFSIZE-1)) fprintf(fp, "\"%s\"", buf); fprintf(fp, "\n"); @@ -6279,7 +6275,7 @@ generic_dump_irq(int irq) readmem(action+OFFSET(irqaction_name), KVADDR, &tmp1, sizeof(void *), "irqaction name", FAULT_ON_ERROR); - if (read_string(tmp1, buf, BUFSIZE-1)) + if (mem_read_string(tmp1, buf, BUFSIZE-1)) fprintf(fp, "\"%s\"", buf); readmem(action+OFFSET(irqaction_next), KVADDR, @@ -6350,7 +6346,7 @@ generic_get_irq_affinity(int irq) &name, sizeof(void *), "irqaction name", FAULT_ON_ERROR); BZERO(buf, BUFSIZE); - if (read_string(name, buf, BUFSIZE-1)) { + if (mem_read_string(name, buf, BUFSIZE-1)) { if (strlen(name_buf) != 0) strncat(name_buf, ",", 2); strncat(name_buf, buf, strlen(buf)); @@ -6459,7 +6455,7 @@ generic_show_interrupts(int irq, ulong *cpus) "hw_interrupt_type typename", FAULT_ON_ERROR); BZERO(buf, BUFSIZE); - if (read_string(tmp, buf, BUFSIZE-1)) + if (mem_read_string(tmp, buf, BUFSIZE-1)) fprintf(fp, "%14s", buf); } else if (VALID_MEMBER(irq_chip_typename)) { @@ -6468,14 +6464,14 @@ generic_show_interrupts(int irq, ulong *cpus) "hw_interrupt_type typename", FAULT_ON_ERROR); BZERO(buf, BUFSIZE); - if (read_string(tmp, buf, BUFSIZE-1)) + if (mem_read_string(tmp, buf, BUFSIZE-1)) fprintf(fp, "%8s", buf); BZERO(buf1, BUFSIZE); if (VALID_MEMBER(irq_desc_t_name)) readmem(irq_desc_addr+OFFSET(irq_desc_t_name), KVADDR, &tmp1, sizeof(void *), "irq_desc name", FAULT_ON_ERROR); - if (read_string(tmp1, buf1, BUFSIZE-1)) + if (mem_read_string(tmp1, buf1, BUFSIZE-1)) fprintf(fp, "-%-8s", buf1); } } @@ -6487,7 +6483,7 @@ generic_show_interrupts(int irq, ulong *cpus) &name, sizeof(void *), "irqaction name", FAULT_ON_ERROR); BZERO(buf2, BUFSIZE); - if (read_string(name, buf2, BUFSIZE-1)) { + if (mem_read_string(name, buf2, BUFSIZE-1)) { if (strlen(name_buf) != 0) strncat(name_buf, ",", 2); strncat(name_buf, buf2, strlen(buf2)); @@ -9057,7 +9053,7 @@ hypervisor_init(void) MEMBER_EXISTS("pv_info", "name") && readmem(symbol_value("pv_info") + MEMBER_OFFSET("pv_info", "name"), KVADDR, &name, sizeof(char *), "pv_info.name", - QUIET|RETURN_ON_ERROR) && read_string(name, buf, BUFSIZE-1)) + QUIET|RETURN_ON_ERROR) && mem_read_string(name, buf, BUFSIZE-1)) kt->hypervisor = strdup(buf); else if (try_get_symbol_data("x86_hyper", sizeof(void *), &x86_hyper)) { if (!x86_hyper) @@ -9065,7 +9061,7 @@ hypervisor_init(void) else if (MEMBER_EXISTS("hypervisor_x86", "name") && readmem(x86_hyper + MEMBER_OFFSET("hypervisor_x86", "name"), KVADDR, &name, sizeof(char *), "x86_hyper->name", - QUIET|RETURN_ON_ERROR) && read_string(name, buf, BUFSIZE-1)) + QUIET|RETURN_ON_ERROR) && mem_read_string(name, buf, BUFSIZE-1)) kt->hypervisor = strdup(buf); } else if (XENDUMP_DUMPFILE() || XEN()) kt->hypervisor = "Xen"; diff --git a/main.c b/main.c index 8917f0fb..ed0fe828 100644 --- a/main.c +++ b/main.c @@ -687,8 +687,12 @@ main(int argc, char **argv) * be called. This can be avoided by always making gdb ignore SIGINT. */ void -main_loop(void) +main_loop(void *ignored) { + if (pc->flags & VERSION_QUERY) { + fprintf(fp, "\n"); + clean_exit(0); + } if (pc->flags2 & ERASEINFO_DATA) error(WARNING, "\n%s:\n " "Kernel data has been erased from this dumpfile. This may " @@ -1780,7 +1784,7 @@ check_xen_hyper(void) static char *untrusted_file_list[4] = { 0 }; int -untrusted_file(FILE *filep, char *filename) +untrusted_file(FILE *filep, const char *filename) { struct stat sbuf; int i; diff --git a/memory.c b/memory.c index 5e7ffe8b..a00d5b04 100644 --- a/memory.c +++ b/memory.c @@ -5952,7 +5952,7 @@ page_flags_init_from_pageflag_names(void) break; } - if (!read_string((ulong)name, namebuf, BUFSIZE-1)) { + if (!mem_read_string((ulong)name, namebuf, BUFSIZE-1)) { error(INFO, "failed to read pageflag_names entry\n", i, name, mask); goto pageflags_fail; @@ -6814,7 +6814,7 @@ dump_free_pages_zones_v1(struct meminfo *fi) readmem(node_zones+OFFSET(zone_struct_name), KVADDR, &value, sizeof(void *), "node_zones name", FAULT_ON_ERROR); - if (read_string(value, buf, BUFSIZE-1)) + if (mem_read_string(value, buf, BUFSIZE-1)) fprintf(fp, "%-9s ", buf); else fprintf(fp, "(unknown) "); @@ -7100,7 +7100,7 @@ dump_free_pages_zones_v2(struct meminfo *fi) readmem(node_zones+OFFSET(zone_name), KVADDR, &value, sizeof(void *), "node_zones name", FAULT_ON_ERROR); - if (read_string(value, buf, BUFSIZE-1) && + if (mem_read_string(value, buf, BUFSIZE-1) && STREQ(buf, "HighMem")) vt->ZONE_HIGHMEM = i; @@ -7147,7 +7147,7 @@ dump_free_pages_zones_v2(struct meminfo *fi) readmem(node_zones+OFFSET(zone_name), KVADDR, &value, sizeof(void *), "node_zones name", FAULT_ON_ERROR); - if (read_string(value, buf, BUFSIZE-1)) + if (mem_read_string(value, buf, BUFSIZE-1)) fprintf(fp, "%-9s ", buf); else fprintf(fp, "(unknown) "); @@ -7418,7 +7418,7 @@ dump_zone_page_usage(void) readmem(node_zones+OFFSET(zone_struct_name), KVADDR, &value, sizeof(void *), "node_zones name", FAULT_ON_ERROR); - if (read_string(value, buf1, BUFSIZE-1)) + if (mem_read_string(value, buf1, BUFSIZE-1)) sprintf(namebuf, "%-8s", buf1); else sprintf(namebuf, "(unknown)"); @@ -8390,7 +8390,7 @@ dump_page_lists(struct meminfo *mi) readmem(node_zones+OFFSET(zone_struct_name), KVADDR, &value, sizeof(void *), "zone_struct name", FAULT_ON_ERROR); - if (!read_string(value, buf, BUFSIZE-1)) + if (!mem_read_string(value, buf, BUFSIZE-1)) sprintf(buf, "(unknown) "); if (mi->flags & VERBOSE) { @@ -8500,7 +8500,7 @@ is_kmem_cache_addr(ulong vaddr, char *kbuf) readmem(cache+name_offset, KVADDR, kbuf, vt->kmem_cache_namelen, "name array", FAULT_ON_ERROR); } else { readmem(cache+name_offset, KVADDR, &name, sizeof(name), "name", FAULT_ON_ERROR); - if (!read_string(name, kbuf, BUFSIZE-1)) { + if (!mem_read_string(name, kbuf, BUFSIZE-1)) { if (vt->flags & (PERCPU_KMALLOC_V1|PERCPU_KMALLOC_V2)) error(WARNING, @@ -8577,7 +8577,7 @@ kmem_cache_list(void) vt->kmem_cache_namelen); } else { name = ULONG(cache_buf + name_offset); - if (!read_string(name, buf, BUFSIZE-1)) { + if (!mem_read_string(name, buf, BUFSIZE-1)) { if (vt->flags & (PERCPU_KMALLOC_V1|PERCPU_KMALLOC_V2)) error(WARNING, @@ -9452,7 +9452,7 @@ dump_kmem_cache(struct meminfo *si) } else { name = ULONG(si->cache_buf + OFFSET(kmem_cache_s_c_name)); - if (!read_string(name, buf, BUFSIZE-1)) { + if (!mem_read_string(name, buf, BUFSIZE-1)) { error(WARNING, "cannot read kmem_cache_s.c_name string at %lx\n", name); @@ -9661,7 +9661,7 @@ dump_kmem_cache_percpu_v1(struct meminfo *si) readmem(si->cache+OFFSET(kmem_cache_s_name), KVADDR, &name, sizeof(ulong), "name", FAULT_ON_ERROR); - if (!read_string(name, buf, BUFSIZE-1)) { + if (!mem_read_string(name, buf, BUFSIZE-1)) { error(WARNING, "cannot read kmem_cache_s.name string at %lx\n", name); @@ -9905,7 +9905,7 @@ dump_kmem_cache_percpu_v2(struct meminfo *si) readmem(si->cache+OFFSET(kmem_cache_s_name), KVADDR, &name, sizeof(ulong), "name", FAULT_ON_ERROR); - if (!read_string(name, buf, BUFSIZE-1)) { + if (!mem_read_string(name, buf, BUFSIZE-1)) { error(WARNING, "cannot read kmem_cache_s.name string at %lx\n", name); @@ -12822,14 +12822,14 @@ phys_to_page(physaddr_t phys, ulong *pp) * for handling it. */ int -read_string(ulong kvaddr, char *buf, int maxlen) +mem_read_string(ulong kvaddr, char *buf, int maxlen) { int i; BZERO(buf, maxlen); readmem(kvaddr, KVADDR, buf, maxlen, - "read_string characters", QUIET|RETURN_ON_ERROR); + "mem_read_string characters", QUIET|RETURN_ON_ERROR); for (i = 0; i < maxlen; i++) { if (buf[i] == NULLCHAR) { @@ -15415,7 +15415,7 @@ dump_memory_nodes(int initialize) readmem(node_zones+OFFSET_OPTION(zone_struct_name, zone_name), KVADDR, &value, sizeof(void *), "zone[_struct] name", FAULT_ON_ERROR); - if (!read_string(value, buf1, BUFSIZE-1)) + if (!mem_read_string(value, buf1, BUFSIZE-1)) sprintf(buf1, "(unknown) "); if (VALID_STRUCT(zone_struct)) { if (VALID_MEMBER(zone_struct_zone_start_paddr)) @@ -15613,7 +15613,7 @@ dump_zone_stats(void) value1 = ULONG(zonebuf + OFFSET_OPTION(zone_struct_name, zone_name)); - if (!read_string(value1, buf1, BUFSIZE-1)) + if (!mem_read_string(value1, buf1, BUFSIZE-1)) sprintf(buf1, "(unknown) "); if (VALID_MEMBER(zone_struct_size)) @@ -17137,7 +17137,7 @@ kmem_cache_list_common(void) KVADDR, &name, sizeof(char *), "kmem_cache.name", FAULT_ON_ERROR); - if (!read_string(name, buf, BUFSIZE-1)) + if (!mem_read_string(name, buf, BUFSIZE-1)) sprintf(buf, "(unknown)\n"); fprintf(fp, "%s\n", buf); @@ -17239,7 +17239,7 @@ dump_kmem_cache_slub(struct meminfo *si) goto next_cache; name = ULONG(si->cache_buf + OFFSET(kmem_cache_name)); - if (!read_string(name, buf, BUFSIZE-1)) + if (!mem_read_string(name, buf, BUFSIZE-1)) sprintf(buf, "(unknown)"); if (reqname) { if (!STREQ(reqname, buf)) @@ -17876,7 +17876,7 @@ is_kmem_cache_addr_common(ulong vaddr, char *kbuf) "kmem_cache.name", RETURN_ON_ERROR)) break; - if (!read_string(name, kbuf, BUFSIZE-1)) + if (!mem_read_string(name, kbuf, BUFSIZE-1)) sprintf(kbuf, "(unknown)"); found = TRUE; @@ -18073,7 +18073,7 @@ is_slab_page(struct meminfo *si, char *buf) "kmem_cache.name", QUIET|RETURN_ON_ERROR)) goto bailout; - if (!read_string(name, buf, BUFSIZE-1)) + if (!mem_read_string(name, buf, BUFSIZE-1)) goto bailout; retval = buf; @@ -18217,7 +18217,7 @@ get_kmem_cache_by_name(char *request) KVADDR, &name, sizeof(char *), "kmem_cache.name", FAULT_ON_ERROR); - if (!read_string(name, buf, BUFSIZE-1)) + if (!mem_read_string(name, buf, BUFSIZE-1)) continue; if (STREQ(buf, request)) { diff --git a/net.c b/net.c index 93491dfb..0f3d8927 100644 --- a/net.c +++ b/net.c @@ -818,7 +818,7 @@ get_device_name(ulong devaddr, char *buf) readmem(devaddr + net->dev_name, KVADDR, &name_addr, sizeof(name_addr), net->dev_name_t, FAULT_ON_ERROR); - read_string(name_addr, buf, DEV_NAME_MAX); + mem_read_string(name_addr, buf, DEV_NAME_MAX); break; } } diff --git a/ppc.c b/ppc.c index cf5bf568..92a19ed3 100644 --- a/ppc.c +++ b/ppc.c @@ -267,7 +267,7 @@ ppc_probe_base_platform(void) int i; if(!try_get_symbol_data("powerpc_base_platform", sizeof(ulong), &ptr) || - read_string(ptr, platform_name, MAX_PLATFORM_LEN - 1) == 0) + mem_read_string(ptr, platform_name, MAX_PLATFORM_LEN - 1) == 0) /* Let us fallback to default definitions */ strcpy(platform_name, "(unknown)"); @@ -731,7 +731,7 @@ ppc_processor_speed(void) FAULT_ON_ERROR); if(type != 0) { - len = read_string(type, str_buf, + len = mem_read_string(type, str_buf, sizeof(str_buf)); if(len && (strcasecmp(str_buf, "cpu") == 0)) @@ -755,7 +755,7 @@ ppc_processor_speed(void) sizeof(ulong), "property name", FAULT_ON_ERROR); - len = read_string(name, str_buf, + len = mem_read_string(name, str_buf, sizeof(str_buf)); if (len && (strcasecmp(str_buf, @@ -1561,7 +1561,7 @@ static void ppc_dump_irq(int irq) /* typename */ readmem(ctl + OFFSET(hw_interrupt_type_typename), KVADDR, &addr, sizeof(ulong), "typename pointer", FAULT_ON_ERROR); - len = read_string(addr, typename, 32); + len = mem_read_string(addr, typename, 32); if(len) fprintf(fp, " typename: %08lx \"%s\"\n", @@ -1675,7 +1675,7 @@ static void ppc_dump_irq(int irq) /* name */ readmem(action + OFFSET(irqaction_name), KVADDR, &addr, sizeof(ulong), "action name", FAULT_ON_ERROR); - len = read_string(addr, typename, 32); + len = mem_read_string(addr, typename, 32); if(len) fprintf(fp, " name: %08lx \"%s\"\n", diff --git a/ppc64.c b/ppc64.c index 2cd9f029..bf17e169 100644 --- a/ppc64.c +++ b/ppc64.c @@ -1071,7 +1071,7 @@ ppc64_processor_speed(void) KVADDR, &type, sizeof(ulong), "node type", FAULT_ON_ERROR); if(type != 0) { - len = read_string(type, str_buf, + len = mem_read_string(type, str_buf, sizeof(str_buf)); if(len && (strcasecmp(str_buf, "cpu") == 0)) @@ -1095,7 +1095,7 @@ ppc64_processor_speed(void) sizeof(ulong), "property name", FAULT_ON_ERROR); - len = read_string(name, str_buf, + len = mem_read_string(name, str_buf, sizeof(str_buf)); if (len && (strcasecmp(str_buf, @@ -2298,7 +2298,7 @@ ppc64_dump_irq(int irq) sizeof(ulong), "typename pointer", FAULT_ON_ERROR); fprintf(fp, " typename: %08lx ", addr); - if (read_string(addr, typename, 32)) + if (mem_read_string(addr, typename, 32)) fprintf(fp, "\"%s\"\n", typename); else fprintf(fp, "\n"); @@ -2412,7 +2412,7 @@ ppc64_dump_irq(int irq) sizeof(ulong), "action name", FAULT_ON_ERROR); fprintf(fp, " name: %08lx ", addr); - if (read_string(addr, typename, 32)) + if (mem_read_string(addr, typename, 32)) fprintf(fp, "\"%s\"\n", typename); else fprintf(fp, "\n"); diff --git a/symbols.c b/symbols.c index 79f13b24..c01e49d7 100644 --- a/symbols.c +++ b/symbols.c @@ -17,10 +17,8 @@ #include "defs.h" #include -#ifdef GDB_7_6 #define __CONFIG_H__ 1 #include "config.h" -#endif #include "bfd.h" static void store_symbols(bfd *, int, void *, long, unsigned int); @@ -430,17 +428,8 @@ separate_debug_file_exists(const char *name, unsigned long crc, int *exists) *exists = TRUE; while ((count = read(fd, buffer, sizeof(buffer))) > 0) -#ifdef GDB_5_3 - file_crc = calc_crc32(file_crc, buffer, count); -#else -#ifdef GDB_7_6 file_crc = bfd_calc_gnu_debuglink_crc32(file_crc, (unsigned char *)buffer, count); -#else - file_crc = gnu_debuglink_crc32(file_crc, - (unsigned char *)buffer, count); -#endif -#endif close (fd); @@ -1367,7 +1356,7 @@ store_module_symbols_v1(ulong total, int mods_installed) size_of_struct = ULONG(modbuf + OFFSET(module_size_of_struct)); - if (!read_string(mod_name, name, BUFSIZE-1)) + if (!mem_read_string(mod_name, name, BUFSIZE-1)) sprintf(name, "(unknown module)"); sprintf(rodata, "__insmod_%s_S.rodata", name); @@ -1447,7 +1436,7 @@ store_module_symbols_v1(ulong total, int mods_installed) strcpy(buf1, &strbuf[(ulong)modsym->name - first]); else - read_string((ulong)modsym->name, buf1, + mem_read_string((ulong)modsym->name, buf1, BUFSIZE-1); if (strlen(buf1)) { @@ -1751,7 +1740,7 @@ store_module_symbols_v2(ulong total, int mods_installed) strcpy(buf1, &strbuf[(ulong)modsym->name - first]); else - read_string((ulong)modsym->name, buf1, + mem_read_string((ulong)modsym->name, buf1, BUFSIZE-1); if (strlen(buf1)) { @@ -1826,7 +1815,7 @@ store_module_symbols_v2(ulong total, int mods_installed) strcpy(buf1, &strbuf[(ulong)modsym->name - first]); else - read_string((ulong)modsym->name, buf1, + mem_read_string((ulong)modsym->name, buf1, BUFSIZE-1); if (strlen(buf1)) { @@ -3613,11 +3602,7 @@ is_system_map(char *s) static int is_bfd_format(char *filename) { -#ifdef GDB_5_3 - struct _bfd *bfd; -#else struct bfd *bfd; -#endif char **matching; if ((bfd = bfd_openr(filename, NULL)) == NULL) @@ -3635,11 +3620,7 @@ is_bfd_format(char *filename) static int is_binary_stripped(char *filename) { -#ifdef GDB_5_3 - struct _bfd *bfd; -#else struct bfd *bfd; -#endif int number_of_symbols; if ((bfd = bfd_openr(filename, NULL)) == NULL) { @@ -4506,13 +4487,12 @@ value_search(ulong value, ulong *offset) for ( ; sp < st->symend; sp++) { if (value == sp->value) { -#if !defined(GDB_5_3) && !defined(GDB_6_0) && !defined(GDB_6_1) if (STRNEQ(sp->name, ".text.")) { spnext = sp+1; if (spnext->value == value) sp = spnext; } -#endif + if (offset) *offset = 0; @@ -5809,7 +5789,7 @@ dereference_pointer(ulong addr, struct datatype_member *dm, ulong flags) fprintf(pc->saved_fp, "<%s> ", sym); if (!target) fprintf(pc->saved_fp, "NULL\n"); - else if (!accessible(target) || !read_string(target, buf1, BUFSIZE-1)) + else if (!accessible(target) || !mem_read_string(target, buf1, BUFSIZE-1)) fprintf(pc->saved_fp, "(not accessible)\n"); else fprintf(pc->saved_fp, "\"%s\"\n", buf1); @@ -10562,9 +10542,6 @@ add_symbol_file_kallsyms(struct load_module *lm, struct gnu_request *req) char section_name[BUFSIZE]; ulong section_vaddr; -#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1) - return FALSE; -#endif if (!(st->flags & (MODSECT_VMASK|MODSECT_UNKNOWN))) { STRUCT_SIZE_INIT(module_sect_attr, "module_sect_attr"); MEMBER_OFFSET_INIT(module_sect_attrs, @@ -10719,7 +10696,7 @@ add_symbol_file_kallsyms(struct load_module *lm, struct gnu_request *req) } BZERO(section_name, BUFSIZE); - if (!read_string(name, section_name, 32)) { + if (!mem_read_string(name, section_name, 32)) { done = TRUE; retval = FALSE; continue; @@ -11727,7 +11704,7 @@ clear_text_value_cache(void) #define last_sp addr2 int -patch_kernel_symbol(struct gnu_request *req) +patch_kernel_symbol(struct gnu_request *req, void *msym) { int i, c; struct syment *sp_array[1000], *sp; @@ -11758,14 +11735,14 @@ patch_kernel_symbol(struct gnu_request *req) return TRUE; } - if (!req->name || !req->addr) + if (!req->name || !msym) return FALSE; sp = (struct syment *)req->last_sp; sp += sp ? 1 : 0; if (sp && (sp->cnt == 1) && !(sp->flags & SYMBOL_NAME_USED) && STREQ(sp->name, req->name)) { - *((ulong *)req->addr) = sp->value; + gdb_patch_minsymbol_address(msym, sp->value); sp->flags |= SYMBOL_NAME_USED; req->last_sp = (ulong)sp; } else { @@ -11775,7 +11752,7 @@ patch_kernel_symbol(struct gnu_request *req) return TRUE; case 1: - *((ulong *)req->addr) = sp_array[0]->value; + gdb_patch_minsymbol_address(msym, sp_array[0]->value); sp_array[0]->flags |= SYMBOL_NAME_USED; req->last_sp = (ulong)sp_array[0]; break; @@ -11784,7 +11761,8 @@ patch_kernel_symbol(struct gnu_request *req) for (i = 0; i < c; i++) { if (sp_array[i]->flags & SYMBOL_NAME_USED) continue; - *((ulong *)req->addr) = sp_array[i]->value; + gdb_patch_minsymbol_address(msym, + sp_array[i]->value); sp_array[i]->flags |= SYMBOL_NAME_USED; req->last_sp = (ulong)sp_array[i]; break; diff --git a/task.c b/task.c index fe459216..fbb91171 100644 --- a/task.c +++ b/task.c @@ -4859,7 +4859,7 @@ initialize_task_state(void) goto old_defaults; bitpos = 0; for (i = 0; i < len; i++) { - if (!read_string(str, buf, BUFSIZE-1)) + if (!mem_read_string(str, buf, BUFSIZE-1)) break; if (CRASHDEBUG(3)) @@ -5448,7 +5448,7 @@ get_panicmsg(char *buf) msg_found = FALSE; if (tt->panicmsg) { - read_string(tt->panicmsg, buf, BUFSIZE-1); + mem_read_string(tt->panicmsg, buf, BUFSIZE-1); msg_found = TRUE; } else if (LKCD_DUMPFILE()) { get_lkcd_panicmsg(buf); @@ -6002,11 +6002,9 @@ foreach(struct foreach_data *fd) error(INFO, "line numbers are not available\n"); fd->flags &= ~FOREACH_l_FLAG; } -#ifndef GDB_5_3 if ((fd->flags & FOREACH_g_FLAG)) error(FATAL, "bt -g option is not supported when issued from foreach\n"); -#endif bt = &bt_info; break; @@ -6180,10 +6178,6 @@ foreach(struct foreach_data *fd) bt->flags |= BT_OLD_BACK_TRACE; if (fd->flags & FOREACH_e_FLAG) bt->flags |= BT_EFRAME_SEARCH; -#ifdef GDB_5_3 - if (fd->flags & FOREACH_g_FLAG) - bt->flags |= BT_USE_GDB; -#endif if (fd->flags & FOREACH_l_FLAG) bt->flags |= BT_LINE_NUMBERS; if (fd->flags & FOREACH_f_FLAG) @@ -8859,7 +8853,7 @@ get_task_group_name(ulong group) readmem(kernfs_node + OFFSET(kernfs_node_name), KVADDR, &name, sizeof(ulong), "kernfs_node name", FAULT_ON_ERROR); - if (!name || !read_string(name, buf, BUFSIZE-1)) + if (!name || !mem_read_string(name, buf, BUFSIZE-1)) return NULL; tmp = GETBUF(strlen(buf)+1); diff --git a/unwind_x86_32_64.c b/unwind_x86_32_64.c index c62f92f5..d245f458 100644 --- a/unwind_x86_32_64.c +++ b/unwind_x86_32_64.c @@ -887,7 +887,7 @@ gather_in_memory_unwind_tables(void) goto gather_failed; name = ULONG(root_table_buf + OFFSET(unwind_table_name)); - if (read_string(name, buf, strlen("kernel")+1) && + if (mem_read_string(name, buf, strlen("kernel")+1) && STREQ("kernel", buf)) { found++; if (CRASHDEBUG(1))