command line dbx : See more source

Okay, so you use dbx from the command line. When dbx stops at a breakpoint, it tells you the source line where you stopped. Well that's nice. But it's usually not enough context to know where you really are. You'd like to see more of the source. You can use the 'list' command to show you the source from that line down, but how can you see the source above and below that line at the same time? Easy. Write a little script. I got this script from someone else in my group, so I can't take credit for it, but now I use it all the time. Put this script in your .dbxrc file, and away you go:
li() {
   list $[$vlineno-5], $[$vlineno-1]
   kprint -n ">"
   list $vlineno
   list $[$vlineno], $[$vlineno+5]
}

Here's what it looks like in use:

stopped in main at line 64 in file "Cdlib.c"
   64     if (argc == 1)
(dbx) li
   59     FILE \*cd_file;
   60     cd_title \*cd_p, \*prev_cd_p, \*cd_p_2;
   61     char cd_info_path[PATH_MAX], \*lp;
   62     int tr;
   63
>   64     if (argc == 1)
   65       sprintf (cd_info_path, "%s/.workmandb", ...
   66     else
   67       strcpy (cd_info_path, argv[1]);
   68
   69     cd_file = fopen (cd_info_path, "r");
   70     if (cd_file == NULL) {
Getting the current line to line up with the others (because of the arrow) even when the first character might be a tab, is left as an exercise for the reader. :-) more later. I'll be on vacation for a week.
Comments:

Hi, Thanks for this writeup! Is this compatible with all compilers? When I used /usr/dist/pkgs/devpro/5.x-sparc/bin/dbx with following .dbxrc file, --------------- dbxenv suppress_startup_message 4.0 li() { list $[$vlineno-5], $[$vlineno-1] kprint -n ">" list $vlineno list $[$vlineno], $[$vlineno+5] } ----------- it generated following error: sr1-umpk-01:/home/kt>dbx (dbx) li dbx: warning: unknown language, 'ansic' assumed dbx: illegal character in number: ',' Use the `help' command for more information. (dbx) Any help would be greatly appreciated. Thanks!btw, sorry for the formatting mess of this text.

Posted by Kuntal Thakore on February 01, 2007 at 07:08 AM PST #

That's a pretty old dbx you've got there. :-) Since I see you are inside Sun, try using the one at this path:
/usr/dist/share/sunstudio_sparc,v10.0/SUNWspro/bin

Posted by Chris Quenelle on February 01, 2007 at 07:08 AM PST #

I think this should work, even on the old version of dbx. It's not very robust, so you will get a strange error if there is no source file. If you start dbx without a program, there will be no source to display.

Posted by Chris Quenelle on February 01, 2007 at 07:08 AM PST #

Post a Comment:
Comments are closed for this entry.
About

Chris Quenelle

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today