problems with line numbering

Daniel Jacobowitz dan@debian.org
Mon Jan 10 21:43:00 GMT 2000


[Background included for the lists]

Platform is ia32, Debian GNU/Linux; gcc is version 2.95.2; gdb is
the snapshots from 19990928 and 20000110.

When trying to debug apache, I ran into the obnoxious problem that
breakpoints in functions were being put too far into the function.
For example:

(gdb) p invoke_cmd
$1 = {char *(command_rec *, cmd_parms *, void *, char *)} 0x8054330 <invoke_cmd>
(gdb) break invoke_cmd
Breakpoint 1 at 0x8054347: file http_config.c, line 810.

A look at the beginning of invoke_cmd shows me:
(gdb) x/20i invoke_cmd
0x8054330 <invoke_cmd>: push   %ebp
0x8054331 <invoke_cmd+1>:       mov    %esp,%ebp
0x8054333 <invoke_cmd+3>:       sub    $0xc,%esp
0x8054336 <invoke_cmd+6>:       push   %edi
0x8054337 <invoke_cmd+7>:       push   %esi
0x8054338 <invoke_cmd+8>:       push   %ebx
0x8054339 <invoke_cmd+9>:       mov    0xc(%ebp),%edx
0x805433c <invoke_cmd+12>:      mov    0x4(%edx),%eax
0x805433f <invoke_cmd+15>:      mov    0x8(%ebp),%edx
0x8054342 <invoke_cmd+18>:      and    0xc(%edx),%eax
0x8054345 <invoke_cmd+21>:      jne    0x8054360 <invoke_cmd+48>
0x8054347 <invoke_cmd+23>:      push   $0x0


Which corresponds to:
static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
                            void *mconfig, const char *args)
{
    char *w, *w2, *w3;
    const char *errmsg;

    if ((parms->override & cmd->req_override) == 0)
        return ap_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);


In other words - that breakpoint is on the inside of the if statement.  Thus
it is not hit in any of the cases I was trying to debug.

[End background]
----

OK, I see where the problem is.

Again, the source chunk with a problem, line numbers added:

803 static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
804                             void *mconfig, const char *args)
805 {
806    char *w, *w2, *w3;
807    const char *errmsg;
808
809    if ((parms->override & cmd->req_override) == 0)
810        return ap_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
811
812    parms->info = cmd->cmd_data;

And the matching assembly:

00000ad0 <invoke_cmd>:
     ad0:       55                      push   %ebp
     ad1:       89 e5                   mov    %esp,%ebp
     ad3:       83 ec 0c                sub    $0xc,%esp
     ad6:       57                      push   %edi
     ad7:       56                      push   %esi
     ad8:       53                      push   %ebx
     ad9:       8b 55 0c                mov    0xc(%ebp),%edx
     adc:       8b 42 04                mov    0x4(%edx),%eax
     adf:       8b 55 08                mov    0x8(%ebp),%edx
     ae2:       23 42 0c                and    0xc(%edx),%eax
     ae5:       75 19                   jne    b00 <invoke_cmd+0x30>
     ae7:       6a 00                   push   $0x0
     ae9:       68 63 02 00 00          push   $0x263
     aee:       ff 32                   pushl  (%edx)
     af0:       8b 45 0c                mov    0xc(%ebp),%eax
     af3:       ff 70 10                pushl  0x10(%eax)
     af6:       e9 28 06 00 00          jmp    1123 <invoke_cmd+0x653>


objdump -g shows something interesting:


  { /* 0xad0 */
    register char *errmsg /* 0x0 */;
    register char *w3 /* 0x2 */;
    register char *w2 /* 0x6 */;
    register char *w /* 0x7 */;
    /* file /usr/src/debug/apache/apache-1.3.9/build-tree/apache_1.3.9/src/main/http_config.c line 805 addr 0xad0 */
    /* file /usr/src/debug/apache/apache-1.3.9/build-tree/apache_1.3.9/src/main/http_config.c line 806 addr 0xad0 */
    /* file /usr/src/debug/apache/apache-1.3.9/build-tree/apache_1.3.9/src/main/http_config.c line 809 addr 0xad0 */
    /* file /usr/src/debug/apache/apache-1.3.9/build-tree/apache_1.3.9/src/main/http_config.c line 810 addr 0xae7 */
    /* file /usr/src/debug/apache/apache-1.3.9/build-tree/apache_1.3.9/src/main/http_config.c line 812 addr 0xb00 */



Note that line 809, the if, is incorrectly listed as starting at 0xad0;
it really starts at ad9.  i386_skip_prologue() in gdb correctly figures
this out, and then calls find_pc_sect_line on it, which says that the
line goes from +ad0 to +ae7; because PROLOGUE_FIRSTLINE_OVERLAP is not
defined, find_function_start_sal() skips ahead to the next line and
breakpoints inside the if.

I'd say this was both a gdb bug and a gcc bug.  The debugging info for
line 809 is definitely wrong, but gdb should be able to cope, IMO.
I can see why PROLOGUE_FIRSTLINE_OVERLAP causes problems, but it
definitely fixes this one.

I'll send the .ii to gcc-bugs in a separate message, it's not relevant
to the gdb list.

Dan

/--------------------------------\  /--------------------------------\
|       Daniel Jacobowitz        |__|        SCS Class of 2002       |
|   Debian GNU/Linux Developer    __    Carnegie Mellon University   |
|         dan@debian.org         |  |       dmj+@andrew.cmu.edu      |
\--------------------------------/  \--------------------------------/


More information about the Gcc-bugs mailing list