Date: Thu, 23 Sep 1999 11:36:03 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: djgpp-workers AT delorie DOT com Subject: Re: symify crashes (fwd) In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp-workers AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Wed, 22 Sep 1999, I wrote: > Anyway, the question is what to do when the combined length of the > function name, the source file name and the line number is more than > 66, which is what's left of the 80-column line after the EIP address. > > I tend to think we should define some reasonable truncation of the > function name and/or the file name, but otherwise leave it at that. Please try this modified version of symify.c. It seems to work for me with some monstrously-long function and file names. If you have any comments about the truncation method I used, please send them. /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include #include #include #include #include #define SC(r,c) (*(char *)(sc + (r)*ScreenCols() + (c))) #define SW(r,c) (*(sc + (r)*ScreenCols() + (c))) void *xmalloc (size_t); void *xrealloc (void *, size_t); TSS a_tss; int main(int argc, char **argv) { int r, c; short *sc; char *buf = NULL; size_t bufsize = 0; int i, lineno; unsigned v; unsigned long d; char *func, *file; FILE *ofile=0; FILE *ifile=0; if (argc < 2) { fprintf(stderr, "Usage: symify [-o ] [-i ] \n"); fprintf(stderr, "This program adds debug information to DJGPP program call frame tracebacks\n"); return 1; } while (argv[1][0] == '-') { if ((strcmp(argv[1], "-o") == 0) && (argc > 3)) { ofile = fopen(argv[2], "w"); if (ofile == 0) fprintf(stderr, "Error: unable to open file %s\n", argv[2]); argc -= 2; argv += 2; } else if ((strcmp(argv[1], "-i") == 0) && (argc > 3)) { ifile = fopen(argv[2], "r"); if (ifile == 0) fprintf(stderr, "Error: unable to open file %s\n", argv[2]); argc -= 2; argv += 2; } else { fprintf(stderr, "Invalid option %s - type `symify' for help\n", argv[1]); exit(1); } } syms_init(argv[1]); if (ifile) { char line[1000]; if (ofile == 0) ofile = stdout; while (fgets(line, 1000, ifile)) { if (strncmp(line, " 0x", 4) == 0) { sscanf(line+4, "%x", &v); func = syms_val2name(v, &d); file = syms_val2line(v, &lineno, 0); fprintf(ofile, " 0x%08x", v); if (func) { fprintf(ofile, " %s", func); if (d) fprintf(ofile, "%+ld", d); } if (file) { if (func) fprintf(ofile, ", "); fprintf(ofile, "line %d of %s", lineno, file); } fputc('\n', ofile); } else fputs(line, ofile); } return 0; } sc = (short *)xmalloc(ScreenRows() * ScreenCols() * 2); ScreenRetrieve(sc); bufsize = ScreenCols() + 10; buf = xmalloc (bufsize); for (r=0; r l_left - 10) { bufsize += l_func + 10; l_left += l_func + 10; buf = xrealloc (buf, bufsize); } strcat(buf, func); l_left -= l_func; if (d) { l_left -= sprintf(buf+l_func, "%+ld", d); l_off = strlen(buf); } } if (file) { l_file = strlen(file); if (l_left < l_file + 25) { bufsize += l_file + 25; l_left += l_file + 25; buf = xrealloc (buf, bufsize); } if (buf[0]) { strcat(buf, ", "); l_left -= 2; } sprintf(buf+strlen(buf), "line %d of %s", lineno, file); l_file = strlen(buf); } if (buf[0]) { int j; int max_func = l_file > ScreenCols() - 13 && l_off > ScreenCols() / 2 - 6 ? ScreenCols() / 2 - 8 - (l_off - l_func) : l_off; int in_func = 1, in_file = 0; /* 0xdeadbeef _FooBar_Func..+666, line 1234 of FooBarF..e.Ext */ /* ^ ^ ^ ^ */ /* 0 l_func l_off l_file */ for (i=0, j=0; buf[j]; i++, j++) { if (i >= ScreenCols()) break; else if (in_func && i >= max_func && j < l_off) { SW(r, 13+i) = 0x0700 + '.'; i++; SW(r, 13+i) = 0x0700 + '.'; i++; j = l_func; /* truncate function name, jump to offset */ in_func = 0; in_file = 1; } else if (in_file && 13+i >= ScreenCols() - 7 && j < l_file - 5) { SW(r, 13+i) = 0x0700 + '.'; i++; SW(r, 13+i) = 0x0700 + '.'; i++; j = l_file - 5; /* jump to last char before extension */ in_file = 0; } SW(r, 13+i) = 0x0f00 + buf[j]; } if (ofile) fprintf (ofile, " %s\n", buf); } } else if (ofile) { c = 0; for (i=0; i