@@ -324,6 +324,27 @@ exprt gdb_value_extractort::get_pointer_to_member_value(
324
324
return *maybe_member_expr;
325
325
}
326
326
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
+ if (function_symbol == nullptr )
340
+ {
341
+ throw invalid_source_file_exceptiont{
342
+ " input source code does not contain function: " + function_name};
343
+ }
344
+ CHECK_RETURN (function_symbol->type .id () == ID_code);
345
+ return function_symbol->symbol_expr ();
346
+ }
347
+
327
348
exprt gdb_value_extractort::get_non_char_pointer_value (
328
349
const exprt &expr,
329
350
const pointer_valuet &value,
@@ -484,9 +505,20 @@ exprt gdb_value_extractort::get_pointer_value(
484
505
const auto target_expr =
485
506
get_pointer_to_member_value (expr, value, location);
486
507
CHECK_RETURN (target_expr.is_not_nil ());
487
- const auto result_expr = address_of_exprt (target_expr);
508
+ const address_of_exprt result_expr{target_expr};
509
+ CHECK_RETURN (result_expr.type () == zero_expr.type ());
510
+ return std::move (result_expr);
511
+ }
512
+
513
+ // pointer to function
514
+ if (expr.type ().subtype ().id () == ID_code)
515
+ {
516
+ const auto target_expr =
517
+ get_pointer_to_function_value (expr, value, location);
518
+ CHECK_RETURN (target_expr.is_not_nil ());
519
+ const address_of_exprt result_expr{target_expr};
488
520
CHECK_RETURN (result_expr.type () == zero_expr.type ());
489
- return result_expr;
521
+ return std::move ( result_expr) ;
490
522
}
491
523
492
524
// non-member: split for char/non-char
@@ -513,20 +545,20 @@ exprt gdb_value_extractort::get_pointer_value(
513
545
CHECK_RETURN (result_indexed_expr.has_value ());
514
546
if (result_indexed_expr->type () == zero_expr.type ())
515
547
return *result_indexed_expr;
516
- const auto result_expr = address_of_exprt {*result_indexed_expr};
548
+ const address_of_exprt result_expr{*result_indexed_expr};
517
549
CHECK_RETURN (result_expr.type () == zero_expr.type ());
518
- return result_expr;
550
+ return std::move ( result_expr) ;
519
551
}
520
552
521
553
// if the types match return right away
522
554
if (target_expr.type () == zero_expr.type ())
523
555
return target_expr;
524
556
525
557
// otherwise the address of target should type-match
526
- const auto result_expr = address_of_exprt ( target_expr) ;
558
+ const address_of_exprt result_expr{ target_expr} ;
527
559
if (result_expr.type () != zero_expr.type ())
528
560
return typecast_exprt{result_expr, zero_expr.type ()};
529
- return result_expr;
561
+ return std::move ( result_expr) ;
530
562
}
531
563
532
564
return zero_expr;
0 commit comments