enum Fruits {Orange, Apple, Banana};
class Fruit
{
int fruit;
public:
Fruit (int f)
{
fruit = f;
}
};
int main()
{
Fruit myFruit(Apple);
return 0; // line 17
}
enum Fruits {Orange, Apple, Banana};
class Fruit
{
int fruit;
public:
Fruit (int f)
{
fruit = f;
}
};
int main()
{
Fruit myFruit(Apple);
return 0; // line 17
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
これは、コマンド g++ -g fruit.cc -o fruit でコンパイルされています。これから、GDB を使ってこのプログラムを検査します。
gdb ./fruit
[...]
(gdb) break 17
Breakpoint 1 at 0x40056d: file fruit.cc, line 17.
(gdb) run
Breakpoint 1, main () at fruit.cc:17
17 return 0; // line 17
(gdb) print myFruit
$1 = {fruit = 1}
gdb ./fruit
[...]
(gdb) break 17
Breakpoint 1 at 0x40056d: file fruit.cc, line 17.
(gdb) run
Breakpoint 1, main () at fruit.cc:17
17 return 0; // line 17
(gdb) print myFruit
$1 = {fruit = 1}
Copy to ClipboardCopied!Toggle word wrapToggle overflow
fruit.py
class FruitPrinter:
def __init__(self, val):
self.val = val
def to_string (self):
fruit = self.val['fruit']
if (fruit == 0):
name = "Orange"
elif (fruit == 1):
name = "Apple"
elif (fruit == 2):
name = "Banana"
else:
name = "unknown"
return "Our fruit is " + name
def lookup_type (val):
if str(val.type) == 'Fruit':
return FruitPrinter(val)
return None
gdb.pretty_printers.append (lookup_type)
fruit.py
class FruitPrinter:
def __init__(self, val):
self.val = val
def to_string (self):
fruit = self.val['fruit']
if (fruit == 0):
name = "Orange"
elif (fruit == 1):
name = "Apple"
elif (fruit == 2):
name = "Banana"
else:
name = "unknown"
return "Our fruit is " + name
def lookup_type (val):
if str(val.type) == 'Fruit':
return FruitPrinter(val)
return None
gdb.pretty_printers.append (lookup_type)
Copy to ClipboardCopied!Toggle word wrapToggle overflow