Skip to content

Commit 8bbcd60

Browse files
committed
Implement extracting function pointers
By simply grabbing the pointee name from gdb (which is the function name) and returning the associated symbol expression.
1 parent 9af7dbb commit 8bbcd60

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/memory-analyzer/analyze_symbol.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,23 @@ exprt gdb_value_extractort::get_pointer_to_member_value(
324324
return *maybe_member_expr;
325325
}
326326

327+
exprt gdb_value_extractort::get_pointer_to_function_value(
328+
const exprt &expr,
329+
const pointer_valuet &pointer_value,
330+
const source_locationt &location)
331+
{
332+
PRECONDITION(expr.type().id() == ID_pointer);
333+
PRECONDITION(expr.type().subtype().id() == ID_code);
334+
PRECONDITION(!pointer_value.address.is_null());
335+
336+
const auto &function_name = pointer_value.pointee;
337+
CHECK_RETURN(!function_name.empty());
338+
const auto function_symbol = symbol_table.lookup(function_name);
339+
CHECK_RETURN(function_symbol != nullptr);
340+
CHECK_RETURN(function_symbol->type.id() == ID_code);
341+
return function_symbol->symbol_expr();
342+
}
343+
327344
exprt gdb_value_extractort::get_non_char_pointer_value(
328345
const exprt &expr,
329346
const pointer_valuet &value,
@@ -489,6 +506,17 @@ exprt gdb_value_extractort::get_pointer_value(
489506
return result_expr;
490507
}
491508

509+
// pointer to function
510+
if(expr.type().subtype().id() == ID_code)
511+
{
512+
const auto target_expr =
513+
get_pointer_to_function_value(expr, value, location);
514+
CHECK_RETURN(target_expr.id() != ID_nil);
515+
const auto result_expr = address_of_exprt(target_expr);
516+
CHECK_RETURN(result_expr.type() == zero_expr.type());
517+
return result_expr;
518+
}
519+
492520
// non-member: split for char/non-char
493521
const auto target_expr =
494522
is_c_char_type(expr.type().subtype())

src/memory-analyzer/analyze_symbol.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,18 @@ class gdb_value_extractort
286286
const pointer_valuet &value,
287287
const source_locationt &location);
288288

289+
/// Extract the function name from \p pointer_value, check it has a symbol and
290+
/// return the associated symbol expression
291+
/// \param expr: the pointer-to-function expression
292+
/// \param pointer_value: pointer value with the function name as the pointee
293+
/// member
294+
/// \param location: the source location
295+
/// \return symbol expression for the function pointed at by \p pointer_value
296+
exprt get_pointer_to_function_value(
297+
const exprt &expr,
298+
const pointer_valuet &pointer_value,
299+
const source_locationt &location);
300+
289301
/// If \p memory_location is found among \ref values then return the symbol
290302
/// expression associated with it.
291303
/// Otherwise we add the appropriate \ref values mapping:

0 commit comments

Comments
 (0)