7
7
8
8
\*******************************************************************/
9
9
10
+ #include < cstdlib>
11
+
10
12
#include " analyze_symbol.h"
11
13
12
14
#include < util/c_types.h>
@@ -29,6 +31,66 @@ gdb_value_extractort::gdb_value_extractort(
29
31
{
30
32
}
31
33
34
+ bool gdb_value_extractort::memory_scopet::contains (
35
+ const memory_addresst &point) const
36
+ {
37
+ size_t begin_int = std::strtoul (begin.address_string .c_str (), NULL , 0 );
38
+ size_t point_int = std::strtoul (point.address_string .c_str (), NULL , 0 );
39
+ return point_int >= begin_int && (begin_int + byte_size) > point_int;
40
+ }
41
+
42
+ mp_integer gdb_value_extractort::memory_scopet::distance (
43
+ const memory_addresst &point,
44
+ mp_integer member_size) const
45
+ {
46
+ CHECK_RETURN (contains (point));
47
+ size_t begin_int = std::strtoul (begin.address_string .c_str (), NULL , 0 );
48
+ size_t point_int = std::strtoul (point.address_string .c_str (), NULL , 0 );
49
+ return (point_int - begin_int) / member_size;
50
+ }
51
+
52
+ std::vector<gdb_value_extractort::memory_scopet>::iterator
53
+ gdb_value_extractort::find_dynamic_allocation (irep_idt name)
54
+ {
55
+ return std::find_if (
56
+ dynamically_allocated.begin (),
57
+ dynamically_allocated.end (),
58
+ [&name](const memory_scopet &scope) { return scope.name == name; });
59
+ }
60
+
61
+ std::vector<gdb_value_extractort::memory_scopet>::iterator
62
+ gdb_value_extractort::find_dynamic_allocation (const memory_addresst &point)
63
+ {
64
+ return std::find_if (
65
+ dynamically_allocated.begin (),
66
+ dynamically_allocated.end (),
67
+ [&point](const memory_scopet &memory_scope) {
68
+ return memory_scope.contains (point);
69
+ });
70
+ }
71
+
72
+ optionalt<mp_integer> gdb_value_extractort::get_malloc_size (irep_idt name)
73
+ {
74
+ const auto scope_it = find_dynamic_allocation (name);
75
+ if (scope_it == dynamically_allocated.end ())
76
+ return {};
77
+ else
78
+ return scope_it->byte_size ;
79
+ }
80
+
81
+ optionalt<std::string> gdb_value_extractort::get_malloc_pointee (
82
+ const memory_addresst &point,
83
+ mp_integer member_size)
84
+ {
85
+ const auto scope_it = find_dynamic_allocation (point);
86
+ if (scope_it == dynamically_allocated.end ())
87
+ return {};
88
+
89
+ const auto pointer_distance = scope_it->distance (point, member_size);
90
+ return id2string (scope_it->name ) +
91
+ (pointer_distance > 0 ? " +" + integer2string (pointer_distance) : " " );
92
+ }
93
+
32
94
void gdb_value_extractort::analyze_symbols (
33
95
const std::vector<std::string> &symbols)
34
96
{
0 commit comments