Skip to content

Commit 7480912

Browse files
author
Christoph Weiss
committed
ocrecord: Move gdb_asm2cfg to separate package
1 parent ff312a8 commit 7480912

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

ocrecord/__init__.py

Whitespace-only changes.

ocgraph/gdb_asm2cfg.py ocrecord/gdb_asm2cfg.py

+30-29
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
For further information see
55
https://sourceware.org/gdb/current/onlinedocs/gdb/Python.html#Python.
66
"""
7-
8-
97
import traceback
108

119
import gdb
1210

13-
from asm2cfg import asm2cfg
11+
from ..ocgraph.interface.drawer import Drawer
12+
from ..ocgraph.interface.analyzer import Analyzer
1413

1514

1615
class SkipCalls(gdb.Parameter):
@@ -20,25 +19,25 @@ class SkipCalls(gdb.Parameter):
2019
set skipcalls off
2120
"""
2221

23-
set_doc = 'Set whether savecfg and viewcfg commands will skip function calls from splitting CFG blocks'
24-
show_doc = 'Set whether savecfg and viewcfg commands will skip function calls from splitting CFG blocks'
22+
set_doc = "Set whether savecfg and viewcfg commands will skip function calls from splitting CFG blocks"
23+
show_doc = "Set whether savecfg and viewcfg commands will skip function calls from splitting CFG blocks"
2524

2625
def __init__(self):
27-
super().__init__('skipcalls', gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)
26+
super().__init__("skipcalls", gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)
2827
self.value = False
2928

3029
def get_set_string(self):
31-
return f'Commands savecfg and viewcfg will skip function calls \
32-
from splitting CFG blocks: {self.value_to_string()}'
30+
return f"Commands savecfg and viewcfg will skip function calls \
31+
from splitting CFG blocks: {self.value_to_string()}"
3332

3433
def get_show_string(self, _):
35-
return f'Commands savecfg and viewcfg will skip function calls \
36-
from splitting CFG blocks: {self.value_to_string()}'
34+
return f"Commands savecfg and viewcfg will skip function calls \
35+
from splitting CFG blocks: {self.value_to_string()}"
3736

3837
def value_to_string(self):
3938
if self.value:
40-
return 'on'
41-
return 'off'
39+
return "on"
40+
return "off"
4241

4342

4443
class ViewCfg(gdb.Command): # pylint: disable=too-few-public-methods
@@ -50,23 +49,25 @@ class ViewCfg(gdb.Command): # pylint: disable=too-few-public-methods
5049
"""
5150

5251
def __init__(self):
53-
super().__init__('viewcfg', gdb.COMMAND_USER)
52+
super().__init__("viewcfg", gdb.COMMAND_USER)
5453

5554
def invoke(self, _arg, _from_tty): # pylint: disable=bad-option-value,no-self-use
56-
""" Called by GDB when viewcfg command is invoked """
55+
"""Called by GDB when viewcfg command is invoked"""
5756
try:
5857
frame = gdb.selected_frame()
5958
arch = frame.architecture().name()
60-
if arch.startswith('i386'):
61-
target_name = 'x86'
62-
elif arch.startswith('arm'):
63-
target_name = 'arm'
59+
if arch.startswith("i386"):
60+
target_name = "x86"
61+
elif arch.startswith("arm"):
62+
target_name = "arm"
63+
elif arch.startswith("sparc"):
64+
target_name = "sparc"
6465
else:
65-
raise RuntimeError(f'unknown platform: {arch}')
66-
assembly_lines = gdb.execute('disassemble', from_tty=False, to_string=True).split('\n')
67-
function_name, basic_blocks = asm2cfg.parse_lines(assembly_lines, gdb.parameter('skipcalls'),
68-
target_name)
69-
asm2cfg.draw_cfg(function_name, basic_blocks, view=True)
66+
raise RuntimeError(f"unknown platform: {arch}")
67+
assembly_lines = gdb.execute("disassemble", from_tty=False, to_string=True).split("\n")
68+
analyzer = Analyzer(config=target_name + " GDB")
69+
analyzer.parse_lines(assembly_lines)
70+
Drawer(analyzer.configuration).view_cfg(analyzer.function_name, analyzer.basic_blocks)
7071
# Catch error coming from GDB side before other errors.
7172
except gdb.error as ex:
7273
raise gdb.GdbError(ex)
@@ -83,15 +84,15 @@ class SaveCfg(gdb.Command): # pylint: disable=too-few-public-methods
8384
"""
8485

8586
def __init__(self):
86-
super().__init__('savecfg', gdb.COMMAND_USER)
87+
super().__init__("savecfg", gdb.COMMAND_USER)
8788

8889
def invoke(self, _arg, _from_tty): # pylint: disable=no-self-use
89-
""" Called by GDB when savecfg command is invoked """
90+
"""Called by GDB when savecfg command is invoked"""
9091
try:
91-
assembly_lines = gdb.execute('disassemble', from_tty=False, to_string=True).split('\n')
92-
function_name, basic_blocks = asm2cfg.parse_lines(assembly_lines, gdb.parameter('skipcalls'),
93-
'x86')
94-
asm2cfg.draw_cfg(function_name, basic_blocks, view=False)
92+
assembly_lines = gdb.execute("disassemble", from_tty=False, to_string=True).split("\n")
93+
analyzer = Analyzer(config="x86 GDB")
94+
analyzer.parse_lines(assembly_lines)
95+
Drawer(analyzer.configuration).view_cfg(analyzer.function_name, analyzer.basic_blocks)
9596
# Catch error coming from GDB side before other errors.
9697
except gdb.error as ex:
9798
raise gdb.GdbError(ex)

0 commit comments

Comments
 (0)