14
14
#include " analyze_symbol.h"
15
15
#include " gdb_api.h"
16
16
17
+ #include < algorithm>
17
18
#include < fstream>
18
19
19
20
#include < ansi-c/ansi_c_language.h>
@@ -67,10 +68,18 @@ int memory_analyzer_parse_optionst::doit()
67
68
const bool core_file = cmdline.isset (" core-file" );
68
69
const bool breakpoint = cmdline.isset (" breakpoint" );
69
70
70
- if (!( core_file ^ breakpoint) )
71
+ if (core_file && breakpoint)
71
72
{
72
73
throw invalid_command_line_argument_exceptiont (
73
- " need to provide either option --core-file or option --breakpoint" , " " );
74
+ " cannot start gdb from both core-file and breakpoint" ,
75
+ " --core-file/--breakpoint" );
76
+ }
77
+
78
+ if (!core_file && !breakpoint)
79
+ {
80
+ throw invalid_command_line_argument_exceptiont (
81
+ " need to provide either core-file or breakpoint for gdb" ,
82
+ " --core-file/--breakpoint" );
74
83
}
75
84
76
85
const bool output_file = cmdline.isset (" output-file" );
@@ -87,20 +96,6 @@ int memory_analyzer_parse_optionst::doit()
87
96
88
97
std::string binary = cmdline.args .front ();
89
98
90
- gdb_apit gdb_api (binary.c_str ());
91
- gdb_api.create_gdb_process ();
92
-
93
- if (core_file)
94
- {
95
- std::string core_file = cmdline.get_value (" core-file" );
96
- gdb_api.run_gdb_from_core (core_file);
97
- }
98
- else if (breakpoint)
99
- {
100
- std::string breakpoint = cmdline.get_value (" breakpoint" );
101
- gdb_api.run_gdb_to_breakpoint (breakpoint);
102
- }
103
-
104
99
const std::string symbol_list (cmdline.get_value (" symbols" ));
105
100
std::vector<std::string> result;
106
101
split_string (symbol_list, ' ,' , result, true , true );
@@ -110,14 +105,32 @@ int memory_analyzer_parse_optionst::doit()
110
105
if (!opt.has_value ())
111
106
{
112
107
throw deserialization_exceptiont (
113
- " cannot read goto binary `" + binary + " ` " );
108
+ " cannot read goto binary `" + binary + " ' " );
114
109
}
115
110
116
111
const goto_modelt goto_model (std::move (opt.value ()));
117
112
118
- symbol_analyzert analyzer (goto_model.symbol_table , gdb_api);
113
+ gdb_value_extractort gdb_value_extractor (
114
+ goto_model.symbol_table , binary.c_str ());
115
+ gdb_value_extractor.create_gdb_process ();
116
+
117
+ if (core_file)
118
+ {
119
+ std::string core_file = cmdline.get_value (" core-file" );
120
+ gdb_value_extractor.run_gdb_from_core (core_file);
121
+ }
122
+ else if (breakpoint)
123
+ {
124
+ std::string breakpoint = cmdline.get_value (" breakpoint" );
125
+ gdb_value_extractor.run_gdb_to_breakpoint (breakpoint);
126
+ }
119
127
120
- analyzer.analyze_symbols (result);
128
+ std::vector<irep_idt> result_ids (result.size ());
129
+ std::transform (
130
+ result.begin (), result.end (), result_ids.begin (), [](std::string &name) {
131
+ return irep_idt{name};
132
+ });
133
+ gdb_value_extractor.analyze_symbols (result_ids);
121
134
122
135
std::ofstream file;
123
136
@@ -131,12 +144,12 @@ int memory_analyzer_parse_optionst::doit()
131
144
132
145
if (symtab_snapshot)
133
146
{
134
- symbol_tablet snapshot = analyzer .get_snapshot_as_symbol_table ();
147
+ symbol_tablet snapshot = gdb_value_extractor .get_snapshot_as_symbol_table ();
135
148
show_symbol_table (snapshot, ui_message_handler);
136
149
}
137
150
else
138
151
{
139
- std::string snapshot = analyzer .get_snapshot_as_c_code ();
152
+ std::string snapshot = gdb_value_extractor .get_snapshot_as_c_code ();
140
153
out << snapshot;
141
154
}
142
155
@@ -163,14 +176,17 @@ void memory_analyzer_parse_optionst::help()
163
176
<< ' \n '
164
177
<< " Usage: Purpose:\n "
165
178
<< ' \n '
166
- << " memory-analyzer [-?] [-h] [--help] show help\n "
167
- << " memory-analyzer --version show version\n "
168
- << " memory-analyzer <options> <binary> analyze binary"
179
+ << " memory-analyzer [-?] [-h] [--help] show help\n "
180
+ << " memory-analyzer --version show"
181
+ << " version\n "
182
+ << " memory-analyzer --symbols <symbol-list> <options> <binary> analyze"
183
+ << " binary\n "
169
184
<< " \n "
170
185
<< " --core-file <file> analyze from core file\n "
171
186
<< " --breakpoint <breakpoint> analyze from breakpoint\n "
172
187
<< " --symbols <symbol-list> list of symbols to analyze\n "
173
188
<< " --symtab-snapshot output snapshot as symbol table\n "
174
189
<< " --output-file <file> write snapshot to file\n "
190
+ << " --json-ui output snapshot in JSON format\n "
175
191
<< messaget::eom;
176
192
}
0 commit comments