[Libguestfs] [PATCH libnbd 0/3] generator: Reset line directive after included code in lib/states.c

Richard W.M. Jones rjones at redhat.com
Fri Dec 3 19:38:49 UTC 2021


On Fri, Dec 03, 2021 at 01:36:19PM -0600, Eric Blake wrote:
> On Fri, Dec 03, 2021 at 07:11:46PM +0000, Richard W.M. Jones wrote:
> > On Fri, Dec 03, 2021 at 07:02:07PM +0000, Richard W.M. Jones wrote:
> > > This restores the #line directives (probably?)  The output looks
> > > right, but I didn't test it beyond opening it in the editor.  Do #line
> > > directives have a way to indicate "current file"?
> > 
> > What I mean is that if you have:
> > 
> > lib/states.c ----------------------------------------
> >   #line 10 "generator/states.c"
> >   ...
> >   #line 20
> > --------------------
> > 
> > does the second #line refer to generator/states.c or lib/states.c?
> 
> Alas, generator/states.c.  Here's how I tested.  In particular, note
> that you MUST use an off-by-one #line directive for the current file
> (the directive #line 10 must appear on line 9, for gdb to display the
> code at line 10 on the next step of the program).

In that case, patch 3 needs something like:

-      let output_loc = "lib/states.c", output_lineno () in
+      let output_loc = "lib/states.c", output_lineno () + 1 in

Rich.

> $ cat foo.c
> #include <stdio.h>
> 
> int main(void)
> {
>     int i = 1;
> #line 1 "bar.c"
>     i++; // real line 7
>     i++; // real line 8
> #line 10
>     i++; // real line 10
>     i++; // real line 11
> #line 13 "foo.c"
>     i++; // real line 13
>     printf("%d\n", i);
>     return 0;
> }
> $ cat bar.c
> i--; // fake line 1
> i--; // fake line 2
> i--; // fake line 3
> i--; // fake line 4
> i--; // fake line 5
> i--; // fake line 6
> i--; // fake line 7
> i--; // fake line 8
> i--; // fake line 9
> i--; // fake line 10
> i--; // fake line 11
> i--; // fake line 12
> i--; // fake line 13
> i--; // fake line 14
> i--; // fake line 15
> $ gcc -g -o foo -Wall foo.c
> $ gdb ./foo
> GNU gdb (GDB) Fedora 11.1-5.fc35
> ...
> (gdb) b main
> Breakpoint 1 at 0x40112e: file foo.c, line 5.
> (gdb) r
> Starting program: /home/eblake/libnbd/foo 
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/lib64/libthread_db.so.1".
> 
> Breakpoint 1, main () at foo.c:5
> 5	    int i = 1;
> (gdb) n
> 1	i--; // fake line 1
> (gdb) 
> 2	i--; // fake line 2
> (gdb) 
> 10	i--; // fake line 10
> (gdb) 
> 11	i--; // fake line 11
> (gdb) 
> 13	    i++; // real line 13
> (gdb) 
> 14	    printf("%d\n", i);
> (gdb) 
> 6
> 15	    return 0;
> (gdb) c
> Continuing.
> [Inferior 1 (process 3800760) exited normally]
> (gdb) q
> 
> 
> 
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.           +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list