* gdbtk.c (gdb_disassemble): Fix problem with source+assembly and
authorStu Grossman <grossman@cygnus>
Tue, 24 Jan 1995 21:49:11 +0000 (21:49 +0000)
committerStu Grossman <grossman@cygnus>
Tue, 24 Jan 1995 21:49:11 +0000 (21:49 +0000)
g++ caused by out-of-order pc's.
* gdbtk.tcl (files_command):  Remove duplicate file names.  Also,
add scrollbar.

gdb/ChangeLog
gdb/gdbtk.c
gdb/gdbtk.tcl

index f597b64..f7ca8ab 100644 (file)
@@ -1,3 +1,10 @@
+Tue Jan 24 12:10:28 1995  Stu Grossman  (grossman@cygnus.com)
+
+       * gdbtk.c (gdb_disassemble):  Fix problem with source+assembly and
+       g++ caused by out-of-order pc's.
+       * gdbtk.tcl (files_command):  Remove duplicate file names.  Also,
+       add scrollbar.
+
 Mon Jan 23 17:21:09 1995  Stu Grossman  (grossman@cygnus.com)
 
        * gdbtk.tcl:  Take .gdbtkinit if it exists.  Makes gdbtk match the
index 7a30458..ca7ef40 100644 (file)
@@ -850,11 +850,12 @@ gdb_disassemble (clientData, interp, argc, argv)
       struct symtab *symtab;
       struct linetable_entry *le;
       int nlines;
+      int newlines;
       struct my_line_entry *mle;
       struct symtab_and_line sal;
       int i;
       int out_of_order;
-      int current_line;
+      int next_line;
 
       symtab = find_pc_symtab (low); /* Assume symtab is valid for whole PC range */
 
@@ -873,45 +874,66 @@ gdb_disassemble (clientData, interp, argc, argv)
 
       out_of_order = 0;
 
-      for (i = 0; i < nlines - 1; i++)
+/* Copy linetable entries for this function into our data structure, creating
+   end_pc's and setting out_of_order as appropriate.  */
+
+/* First, skip all the preceding functions.  */
+
+      for (i = 0; i < nlines - 1 && le[i].pc < low; i++) ;
+
+/* Now, copy all entries before the end of this function.  */
+
+      newlines = 0;
+      for (; i < nlines - 1 && le[i].pc < high; i++)
        {
-         mle[i].line = le[i].line;
+         if (le[i].line == le[i + 1].line
+             && le[i].pc == le[i + 1].pc)
+           continue;           /* Ignore duplicates */
+
+         mle[newlines].line = le[i].line;
          if (le[i].line > le[i + 1].line)
            out_of_order = 1;
-         mle[i].start_pc = le[i].pc;
-         mle[i].end_pc = le[i + 1].pc;
+         mle[newlines].start_pc = le[i].pc;
+         mle[newlines].end_pc = le[i + 1].pc;
+         newlines++;
        }
 
-      mle[i].line = le[i].line;
-      mle[i].start_pc = le[i].pc;
-      sal = find_pc_line (le[i].pc, 0);
-      mle[i].end_pc = sal.end;
+/* If we're on the last line, and it's part of the function, then we need to
+   get the end pc in a special way.  */
+
+      if (i == nlines - 1
+         && le[i].pc < high)
+       {
+         mle[newlines].line = le[i].line;
+         mle[newlines].start_pc = le[i].pc;
+         sal = find_pc_line (le[i].pc, 0);
+         mle[newlines].end_pc = sal.end;
+         newlines++;
+       }
 
 /* Now, sort mle by line #s (and, then by addresses within lines). */
 
       if (out_of_order)
-       qsort (mle, nlines, sizeof (struct my_line_entry), compare_lines);
-
-/* Scan forward until we find the start of the function.  */
-
-      for (i = 0; i < nlines; i++)
-       if (mle[i].start_pc >= low)
-         break;
+       qsort (mle, newlines, sizeof (struct my_line_entry), compare_lines);
 
 /* Now, for each line entry, emit the specified lines (unless they have been
    emitted before), followed by the assembly code for that line.  */
 
-      current_line = 0;                /* Force out first line */
-      for (;i < nlines && mle[i].start_pc < high; i++)
+      next_line = 0;           /* Force out first line */
+      for (i = 0; i < newlines; i++)
        {
-         if (mle[i].line > current_line)
+/* Print out everything from next_line to the current line.  */
+
+         if (mle[i].line >= next_line)
            {
-             if (i == nlines - 1)
-               print_source_lines (symtab, mle[i].line, INT_MAX, 0);
+             if (next_line != 0)
+               print_source_lines (symtab, next_line, mle[i].line + 1, 0);
              else
-               print_source_lines (symtab, mle[i].line, mle[i + 1].line, 0);
-             current_line = mle[i].line;
+               print_source_lines (symtab, mle[i].line, mle[i].line + 1, 0);
+
+             next_line = mle[i].line + 1;
            }
+
          for (pc = mle[i].start_pc; pc < mle[i].end_pc; )
            {
              QUIT;
index 2a16424..92f32b9 100644 (file)
@@ -1701,12 +1701,36 @@ proc files_command {} {
 
        wm minsize .files_window 1 1
 #      wm overrideredirect .files_window true
-       listbox .files_window.list -geometry 30x20 -setgrid true
+       listbox .files_window.list -geometry 30x20 -setgrid true \
+               -yscrollcommand {.files_window.scroll set} -relief raised \
+               -borderwidth 2
+       scrollbar .files_window.scroll -orient vertical \
+               -command {.files_window.list yview}
        button .files_window.close -text Close -command {destroy .files_window}
        tk_listboxSingleSelect .files_window.list
-       eval .files_window.list insert 0 [lsort [gdb_listfiles]]
-       pack .files_window.list -side top -fill both -expand yes
+
+# Get the file list from GDB, sort it, and format it as one entry per line.
+
+       set filelist [join [lsort [gdb_listfiles]] "\n"]
+
+# Now, remove duplicates (by using uniq)
+
+       set fh [open "| uniq > /tmp/gdbtk.[pid]" w]
+       puts $fh $filelist
+       close $fh
+       set fh [open /tmp/gdbtk.[pid]]
+       set filelist [split [read $fh] "\n"]
+       set filelist [lrange $filelist 0 [expr [llength $filelist] - 2]]
+       close $fh
+       exec rm /tmp/gdbtk.[pid]
+
+# Insert the file list into the widget
+
+       eval .files_window.list insert 0 $filelist
+
        pack .files_window.close -side bottom -fill x -expand no -anchor s
+       pack .files_window.scroll -side right -fill both
+       pack .files_window.list -side left -fill both -expand yes
        bind .files_window.list <Any-ButtonRelease-1> {
                set file [%W get [%W curselection]]
                gdb_cmd "list $file:1,0"