Skip to content

Commit 5a64ecc

Browse files
petr-bauchdanpoe
authored andcommitted
Address comments in analyze_symbol.cpp
With a small change in the parser (string->irep_idt).
1 parent 6e6e569 commit 5a64ecc

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/memory-analyzer/analyze_symbol.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,21 @@ gdb_value_extractort::gdb_value_extractort(
2222
symbol_table(symbol_table),
2323
ns(symbol_table),
2424
c_converter(ns, expr2c_configurationt::clean_configuration),
25-
allocate_objects(ID_C, source_locationt(), "", this->symbol_table)
25+
allocate_objects(ID_C, source_locationt(), irep_idt{}, this->symbol_table)
2626
{
2727
}
2828

29-
void gdb_value_extractort::analyze_symbols(
30-
const std::vector<std::string> &symbols)
29+
void gdb_value_extractort::analyze_symbols(const std::vector<irep_idt> &symbols)
3130
{
3231
// record addresses of given symbols
3332
for(const auto &id : symbols)
3433
{
35-
const symbol_exprt symbol_expr(id, typet());
34+
const symbol_exprt &symbol_expr = ns.lookup(id).symbol_expr();
3635
const address_of_exprt aoe(symbol_expr);
3736

3837
const std::string c_expr = c_converter.convert(aoe);
3938
const pointer_valuet &value = gdb_api.get_memory(c_expr);
40-
CHECK_RETURN(value.pointee.empty() || (value.pointee == id));
39+
CHECK_RETURN(value.pointee.empty() || (id == value.pointee));
4140

4241
values.insert({value.address, symbol_expr});
4342
}
@@ -143,12 +142,11 @@ exprt gdb_value_extractort::get_char_pointer_value(
143142
std::string c_expr = c_converter.convert(expr);
144143
pointer_valuet value = gdb_api.get_memory(c_expr);
145144
CHECK_RETURN(value.string);
146-
std::string string = *value.string;
147145

148-
string_constantt init(string);
146+
string_constantt init(*value.string);
149147
CHECK_RETURN(to_array_type(init.type()).is_complete());
150148

151-
symbol_exprt dummy(pointer_typet(init.type(), config.ansi_c.pointer_width));
149+
symbol_exprt dummy("tmp", pointer_type(init.type()));
152150
code_blockt assignments;
153151

154152
const symbol_exprt new_symbol =
@@ -184,7 +182,7 @@ exprt gdb_value_extractort::get_non_char_pointer_value(
184182

185183
const typet target_type = expr.type().subtype();
186184

187-
symbol_exprt dummy(expr.type());
185+
symbol_exprt dummy("tmp", expr.type());
188186
code_blockt assignments;
189187

190188
const symbol_exprt new_symbol =
@@ -284,6 +282,7 @@ exprt gdb_value_extractort::get_expr_value(
284282
PRECONDITION(expr.type() == zero_expr.type());
285283

286284
const typet &type = expr.type();
285+
PRECONDITION(type.id() != ID_struct);
287286

288287
if(is_c_integral_type(type))
289288
{
@@ -310,7 +309,7 @@ exprt gdb_value_extractort::get_expr_value(
310309
return convert_member_name_to_enum_value(
311310
get_gdb_value(expr), to_c_enum_type(type));
312311
}
313-
else if(type.id() == ID_struct || type.id() == ID_struct_tag)
312+
else if(type.id() == ID_struct_tag)
314313
{
315314
return get_struct_value(expr, zero_expr, location);
316315
}
@@ -324,7 +323,7 @@ exprt gdb_value_extractort::get_expr_value(
324323

325324
return get_pointer_value(expr, zero_expr, location);
326325
}
327-
UNREACHABLE;
326+
UNIMPLEMENTED;
328327
}
329328

330329
exprt gdb_value_extractort::get_struct_value(

src/memory-analyzer/analyze_symbol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class gdb_value_extractort
4040
/// \ref symbol_exprt (via the `values` map) and then call
4141
/// \ref analyze_symbol on it.
4242
/// \param symbols: names of symbols to be analysed
43-
void analyze_symbols(const std::vector<std::string> &symbols);
43+
void analyze_symbols(const std::vector<irep_idt> &symbols);
4444

4545
/// Get memory snapshot as C code
4646
/// \return converted block of code with the collected assignments

src/memory-analyzer/memory_analyzer_parse_options.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Malte Mues <[email protected]>
1414
#include "analyze_symbol.h"
1515
#include "gdb_api.h"
1616

17+
#include <algorithm>
1718
#include <fstream>
1819

1920
#include <ansi-c/ansi_c_language.h>
@@ -123,7 +124,13 @@ int memory_analyzer_parse_optionst::doit()
123124
std::string breakpoint = cmdline.get_value("breakpoint");
124125
gdb_value_extractor.run_gdb_to_breakpoint(breakpoint);
125126
}
126-
gdb_value_extractor.analyze_symbols(result);
127+
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);
127134

128135
std::ofstream file;
129136

@@ -169,9 +176,11 @@ void memory_analyzer_parse_optionst::help()
169176
<< '\n'
170177
<< "Usage: Purpose:\n"
171178
<< '\n'
172-
<< " memory-analyzer [-?] [-h] [--help] show help\n"
173-
<< " memory-analyzer --version show version\n"
174-
<< " 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"
175184
<< "\n"
176185
<< " --core-file <file> analyze from core file\n"
177186
<< " --breakpoint <breakpoint> analyze from breakpoint\n"

0 commit comments

Comments
 (0)