2

I am using GDB from a console in a pre-configured environment and the version that it provides has a few bugs. The most annoying one is that, sometimes, when stepping into functions or adding breakpoints or printing the call stack, it spews out hundreds of consecutive lines similar to this one:

warning: Range for type (null) has invalid bounds 0..-103

The only reference I could find for this issue is here and it isn't helpful.

Given the above, I thought it should be simple to either

  1. instruct GDB to suppress such warnings - looks like a dead end. As far as I can tell, GDB doesn't allow users to suppress such warnings.

  2. intercept them in a hook via .gdbinit - seems promising. I was able to change the terminal colour, for example, by poking through the .gdbinit file referenced in this answer. Unfortunately, I couldn't find any hook in the documentation that would be useful for my purpose.

  3. filter the warnings (maybe via some sort of proxy between stdout and GDB) - feels hackish, but I wouldn't mind doing this, if it would somehow work. A stupid attempt was to redirect stderr to /dev/null like so: gdb -p xxxxxx 2> /dev/null, but it looks like the warnings are actually pushed to stdout. Bummer. Then I also thought that maybe I could do something silly such as filtering stdout via grep like so gdb -p xxxxxx | grep -v ^warning, but this seems to have the unwanted side effect of making the terminal prompt invisible for some reason.

Does anyone have some idea what could work? I searched quite a lot for something that might help me implement the 3rd idea, but, so far, I came out empty-handed...

Community
  • 1
  • 1
Mihai Todor
  • 8,014
  • 9
  • 49
  • 86
  • Just a theory: maybe it's possible to avoid the errors by manipulating somewhat the symbolic information inside the binary. I know there are some tools to strip selected symbols. It appears that your gdb misinterprets some array types. But I have no idea how to do it (and it would anyway reduce the debugger's functionality). – Giuseppe Guerrini Feb 13 '15 at 20:44
  • In my situation, that sounds like a bigger pain in the ass than simply getting a newer version of GDB... Then again, indeed, it's another option on the table, but I think I'd need to go deep into the internals of GDB to figure out what on earth it doesn't like from those array symbols. – Mihai Todor Feb 13 '15 at 21:23
  • 1
    If you have a C compiler, it should be easy to take this simple version of [script](http://man7.org/tlpi/code/online/dist/pty/script.c.html) , remove the parts that write to a log file, and add code to filter out any lines you don't want to see. – Mark Plotnick Feb 14 '15 at 20:55
  • Looks like I'd have to put some research work into adjusting it for my needs... I'm still surprised that bash doesn't offer a simple mechanism for achieving what I want. – Mihai Todor Feb 14 '15 at 21:32

1 Answers1

1

First, there's no way in gdb to filter warnings. The warning mechanism isn't programmable from the CLI or the Python layer.

Upgrading gdb might help -- but it might not. From my reading of the link you provided, it sounds like the issue has to do with Fortran variable length arrays ("VLA"). Last I heard this feature was still being worked on in gdb. It is worth a try but I wouldn't count on it.

If the warning doesn't interfere with your work, you could simply hack gdb to remove the warning. This should be pretty straightforward -- simpler than the next idea.

If you really want a wrapper to eliminate the warnings, either (1) run gdb in emacs and hack in some elisp to drop these messages; or (2) use expect to wrap the gdb command line in something that drops the warnings.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63
  • While it would be appealing to hack GDB and remove the silly warning, it's the least portable thing to do and it also involves building GDB... Your suggestion to leverage `emacs` or `expect` sounds promising and I might give it a shot, but I was hoping for a much simpler solution, like some bash script that acts as a transparent wrapper for GDB. It feels like this should be easy to do, but, somehow, I can't seem to find any useful example... – Mihai Todor Feb 14 '15 at 13:01
  • It's up to you, but IMO it's many times simpler to grep for the warning and hack it out than it is to write this wrapper. gdb does not have many dependencies. That said, you might try an existing wrapper for gdb, using MI, like cgdb. – Tom Tromey Feb 15 '15 at 03:25