Chris Quenelle is a tools developer at Oracle Corp. He's worked on performance and debugging tools at Sun and Oracle for over 15 years. He reads comic books and science fiction, and has more tivos than he can keep track of.

 

September 2010
S M T W T F S
« Jun    
 1234
567891011
12131415161718
19202122232425
2627282930  

See more source in dbx

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.

http://quenelle.org/unix/wp-content/plugins/sociofluid/images/digg_24.png http://quenelle.org/unix/wp-content/plugins/sociofluid/images/reddit_24.png http://quenelle.org/unix/wp-content/plugins/sociofluid/images/dzone_24.png http://quenelle.org/unix/wp-content/plugins/sociofluid/images/stumbleupon_24.png http://quenelle.org/unix/wp-content/plugins/sociofluid/images/delicious_24.png http://quenelle.org/unix/wp-content/plugins/sociofluid/images/furl_24.png http://quenelle.org/unix/wp-content/plugins/sociofluid/images/technorati_24.png http://quenelle.org/unix/wp-content/plugins/sociofluid/images/facebook_24.png http://quenelle.org/unix/wp-content/plugins/sociofluid/images/twitter_24.png

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>