4
4
For further information see
5
5
https://sourceware.org/gdb/current/onlinedocs/gdb/Python.html#Python.
6
6
"""
7
-
8
-
9
7
import traceback
10
8
11
9
import gdb
12
10
13
- from asm2cfg import asm2cfg
11
+ from ..ocgraph .interface .drawer import Drawer
12
+ from ..ocgraph .interface .analyzer import Analyzer
14
13
15
14
16
15
class SkipCalls (gdb .Parameter ):
@@ -20,25 +19,25 @@ class SkipCalls(gdb.Parameter):
20
19
set skipcalls off
21
20
"""
22
21
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"
25
24
26
25
def __init__ (self ):
27
- super ().__init__ (' skipcalls' , gdb .COMMAND_DATA , gdb .PARAM_BOOLEAN )
26
+ super ().__init__ (" skipcalls" , gdb .COMMAND_DATA , gdb .PARAM_BOOLEAN )
28
27
self .value = False
29
28
30
29
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 ()} "
33
32
34
33
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 ()} "
37
36
38
37
def value_to_string (self ):
39
38
if self .value :
40
- return 'on'
41
- return ' off'
39
+ return "on"
40
+ return " off"
42
41
43
42
44
43
class ViewCfg (gdb .Command ): # pylint: disable=too-few-public-methods
@@ -50,23 +49,25 @@ class ViewCfg(gdb.Command): # pylint: disable=too-few-public-methods
50
49
"""
51
50
52
51
def __init__ (self ):
53
- super ().__init__ (' viewcfg' , gdb .COMMAND_USER )
52
+ super ().__init__ (" viewcfg" , gdb .COMMAND_USER )
54
53
55
54
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"""
57
56
try :
58
57
frame = gdb .selected_frame ()
59
58
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"
64
65
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 )
70
71
# Catch error coming from GDB side before other errors.
71
72
except gdb .error as ex :
72
73
raise gdb .GdbError (ex )
@@ -83,15 +84,15 @@ class SaveCfg(gdb.Command): # pylint: disable=too-few-public-methods
83
84
"""
84
85
85
86
def __init__ (self ):
86
- super ().__init__ (' savecfg' , gdb .COMMAND_USER )
87
+ super ().__init__ (" savecfg" , gdb .COMMAND_USER )
87
88
88
89
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"""
90
91
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 )
95
96
# Catch error coming from GDB side before other errors.
96
97
except gdb .error as ex :
97
98
raise gdb .GdbError (ex )
0 commit comments