0

When debugging a source file that is full of #line directives the debugger "switches" between those files accordingly.

Issue: only one file is intended to be debugged

Example: As an example one can use yacc/bison lex/flex which translate a grammar to C source. The result is something like this (the actual content is irrelevant to the question, this is just the first sample that I've looked at):

  case 50:
#line 918 "parse.y" /* yacc.c:1652  */
    {
    struct my_struct    *p;

    p = ppp_define_add (ppp_setvar_list, (yyvsp[-3].s), (yyvsp[-1].s), (yyvsp[0].ui));
    if (p) {
        ppp_last_entry = p;
    }
  }
#line 2330 "parse.c" /* yacc.c:1652  */
    break;

  case 51:
#line 927 "parse.y" /* yacc.c:1652  */
    {
    struct my_struct    *p;
    size_t          size;

When debugging code like this GDB shows the original source or generated and compiled source, depending on the actual position which is fine in general. The problem arises if you only want to debug one of those files (which in most cases will be the original source).

Things I've tried so far:

  1. delete the file one doesn't want to skip through.

    144 parse.c: No such file or directory.

  2. skip file when GDB showed the "unwanted" file. This strangely leads GDB (8.2.1) to still go back to the file, just only output that we're in there:

157     in parse.c
(gdb) s
159     in parse.c
(gdb) s
160     in parse.c
(gdb) s
161     in parse.c

Questions:

  1. Is there an option in GDB to only skip/next into a specific file (in this case parse.y)?
  2. Is there an option to strip the debugging information for only parse.c or parse.y from the binary?

Ideally the backtrace bt and similar commands will only show parse.y.

Simon Sobisch
  • 6,263
  • 1
  • 18
  • 38
  • Where did `#line 2330 "parse.c"` come from? `bison` is *not* supposed to generate such lines. Re: debugging only `parse.c` -- https://stackoverflow.com/a/45474518/50617 – Employed Russian Nov 27 '19 at 01:37
  • `bison` and `flex` normally insert those which is reasonable as you compile the generated file (rule of thumb: if you add something like `#line 123 "origin.stuff"` you also should generate `#line 123 "generated.stuff"` for things that are outside of the origin). – Simon Sobisch Nov 27 '19 at 18:49

1 Answers1

0

GDB does not have a "skip everything except this" option. You can skip files and/or functions (possible using a pattern). Therefore, you best option is to add the names of the files (or use a pattern) to your .gdbinit file.

But by using the Python API we can do much more with GDB. This question has a lot of useful information. Particularly, the last answer seems very similar to what you want.

darcamo
  • 3,294
  • 1
  • 16
  • 27
  • Actually ignoring in any way seems to not work, I _assume_ that this is only handled when the frame changes - and in this case the frame is always the same. The [referenced answer](https://stackoverflow.com/a/49200729/5027456) does work "somehow" (currently leaving a bunch of unwanted output in gdb, but this possibly can be adjusted). Note: I' don't look for "skip everything but", I just look for "not include this specific file, even on the same frame". – Simon Sobisch Apr 13 '21 at 19:25