File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 24
24
#include < goto-programs/goto_model.h>
25
25
26
26
#include < util/prefix.h>
27
+ #include < util/string2int.h>
27
28
#include < util/string_utils.h>
28
29
29
30
#include < sys/wait.h>
@@ -56,6 +57,39 @@ gdb_apit::~gdb_apit()
56
57
wait (NULL );
57
58
}
58
59
60
+ size_t gdb_apit::query_malloc_size (const std::string &pointer_expr)
61
+ {
62
+ write_to_gdb (" -var-create tmp * malloc_usable_size(" + pointer_expr + " )" );
63
+
64
+ if (!was_command_accepted ())
65
+ {
66
+ return 1 ;
67
+ }
68
+
69
+ write_to_gdb (" -var-evaluate-expression tmp" );
70
+ gdb_output_recordt record = get_most_recent_record (" ^done" , true );
71
+
72
+ write_to_gdb (" -var-delete tmp" );
73
+ check_command_accepted ();
74
+
75
+ const auto it = record.find (" value" );
76
+ CHECK_RETURN (it != record.end ());
77
+
78
+ const std::string value = it->second ;
79
+
80
+ INVARIANT (
81
+ value.back () != ' "' ||
82
+ (value.length () >= 2 && value[value.length () - 2 ] == ' \\ ' ),
83
+ " quotes should have been stripped off from value" );
84
+ INVARIANT (value.back () != ' \n ' , " value should not end in a newline" );
85
+
86
+ const auto result = string2optional_size_t (value);
87
+ if (result.has_value ())
88
+ return *result;
89
+ else
90
+ return 1 ;
91
+ }
92
+
59
93
void gdb_apit::create_gdb_process ()
60
94
{
61
95
PRECONDITION (gdb_state == gdb_statet::NOT_CREATED);
Original file line number Diff line number Diff line change @@ -83,6 +83,17 @@ class gdb_apit
83
83
const optionalt<std::string> string;
84
84
};
85
85
86
+ // / Get the allocated size estimate for a pointer by evaluating
87
+ // / `malloc_usable_size'. The function returns the number of usable bytes in
88
+ // / the block pointed to by the pointer to a block of memory allocated by
89
+ // / `malloc' or a related function. The value may be greater than the
90
+ // / requested size of the allocation because of alignment and minimum size
91
+ // / constraints.
92
+ // / \param pointer_expr: expression with a pointer name
93
+ // / \return 1 if the pointer was not allocated with malloc otherwise return
94
+ // / the result of calling `malloc_usable_size'
95
+ size_t query_malloc_size (const std::string &pointer_expr);
96
+
86
97
// / Create a new gdb process for analysing the binary indicated by the member
87
98
// / variable `binary`
88
99
void create_gdb_process ();
You can’t perform that action at this time.
0 commit comments