This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug python/10344] Pretty printers that call into inferior could crash GDB


------- Additional Comments From pmuldoon at redhat dot com  2009-09-24 16:15 -------
Increasing the MAX_UI_OUT_LEVELS will fix the bug as reported, but it will not
help when a situation occurs where the the printers can end up recursing (and
gobbling up the ui levels). Example.

--- cut --- t2.cc ---

#include <stdio.h>

struct Foo;
struct Recurse;

struct Foo {
  Foo() : p(0) { }
  const char *print(Recurse b) const;
  char **p;
};

struct Recurse {
  Recurse (): p (0) { }
  const char *crash(Foo f) const;
  char **p;
};

const char *Recurse::crash(Foo f) const
{
  return *p; // crash as well
}

const char *Foo::print(Recurse b) const
{
  return *p; // crash!
}

char **bar(Foo f)
{
  return f.p;
}

int main()
{
   Foo f;
   Recurse b;
   bar(f);
   return 0;
}

--- cut --- t2.py ---
# Pretty printer for Foo, which calls into inferior

import gdb

class FooPrinter:

  def __init__(self, val):
    self.val = val

  def to_string(self):
    x = self.val.address
    return gdb.parse_and_eval('Foo::print(%s,f)' % str(x))

class RecursePrinter:
  def __init__(self, val):
    self.val = val

  def to_string(self):
    x = self.val.address
    return gdb.parse_and_eval('Recurse::crash(%s,b)' % str(x))


def lookup(val):
  if str(val.type) == "Foo":
    return FooPrinter(val)
  else:
    if str(val.type) == "Recurse":
      return RecursePrinter(val)
    else:
      return None

gdb.pretty_printers = [ lookup ]


I also increased the max MAX_UI_OUT_LEVELS to 15. But it does not matter, it can
be 1000, the result is the same.

-- Test case

./gdb -ex 'source /home/pmuldoon/pp/t.py' -ex 'break bar' -ex 'run'
/home/pmuldoon/pp/t2

Output
Breakpoint 1, bar (f=
Program received signal SIGSEGV, Segmentation fault.
0x000000000040057f in Foo::print (this=0x7fffffffe170, b=
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400567 in Recurse::crash (this=0x7fffffffe0e0, f=
Program received signal SIGSEGV, Segmentation fault.
0x000000000040057f in Foo::print (this=0x7fffffffe050, b=
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400567 in Recurse::crash (
../../archer/gdb/ui-out.c:129: internal-error: push_level: Assertion
`uiout->level >= 0 && uiout->level < MAX_UI_OUT_LEVELS' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) q




-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=10344

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]