Skip to content

Commit d72ba17

Browse files
gdb: dwarf2 generic implementation for caching function data
When there is no dwarf2 data for a register, a function can be called to provide the value of this register. In some situations, it might not be trivial to determine the value to return and it would cause a performance bottleneck to do the computation each time. This patch allows the called function to have a "cache" object that it can use to store some metadata between calls to reduce the performance impact of the complex logic. The cache object is unique for each function and frame, so if there are more than one function pointer stored in the dwarf2_frame_cache->reg array, then the appropriate pointer will be supplied (the type is not known by the dwarf2 implementation). dwarf2_frame_get_fn_data can be used to retrieve the function unique cache object. dwarf2_frame_allocate_fn_data can be used to allocate and retrieve the function unique cache object. Signed-off-by: Torbjörn SVENSSON <[email protected]> Signed-off-by: Yvan Roux <[email protected]>
1 parent 6121eeb commit d72ba17

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

gdb/dwarf2/frame.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,22 @@ dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc,
831831
}
832832

833833

834+
/* Custom function data object for architecture specific prev_register
835+
implementation. Main purpose of this object is to allow caching of
836+
expensive data lookups in the prev_register handling. */
837+
838+
struct dwarf2_frame_fn_data
839+
{
840+
/* The cookie to identify the custom function data by. */
841+
fn_prev_register cookie;
842+
843+
/* The custom function data. */
844+
void *data;
845+
846+
/* Pointer to the next custom function data object for this frame. */
847+
struct dwarf2_frame_fn_data *next;
848+
};
849+
834850
struct dwarf2_frame_cache
835851
{
836852
/* DWARF Call Frame Address. */
@@ -862,6 +878,8 @@ struct dwarf2_frame_cache
862878
dwarf2_tailcall_frame_unwind unwinder so this field does not apply for
863879
them. */
864880
void *tailcall_cache;
881+
882+
struct dwarf2_frame_fn_data *fn_data;
865883
};
866884

867885
static struct dwarf2_frame_cache *
@@ -1221,6 +1239,48 @@ dwarf2_frame_prev_register (frame_info_ptr this_frame, void **this_cache,
12211239
}
12221240
}
12231241

1242+
/* See frame.h. */
1243+
1244+
void *
1245+
dwarf2_frame_get_fn_data (frame_info_ptr this_frame, void **this_cache,
1246+
fn_prev_register cookie)
1247+
{
1248+
struct dwarf2_frame_fn_data *fn_data = nullptr;
1249+
struct dwarf2_frame_cache *cache
1250+
= dwarf2_frame_cache (this_frame, this_cache);
1251+
1252+
/* Find the object for the function. */
1253+
for (fn_data = cache->fn_data; fn_data; fn_data = fn_data->next)
1254+
if (fn_data->cookie == cookie)
1255+
return fn_data->data;
1256+
1257+
return nullptr;
1258+
}
1259+
1260+
/* See frame.h. */
1261+
1262+
void *
1263+
dwarf2_frame_allocate_fn_data (frame_info_ptr this_frame, void **this_cache,
1264+
fn_prev_register cookie, unsigned long size)
1265+
{
1266+
struct dwarf2_frame_fn_data *fn_data = nullptr;
1267+
struct dwarf2_frame_cache *cache
1268+
= dwarf2_frame_cache (this_frame, this_cache);
1269+
1270+
/* First try to find an existing object. */
1271+
void *data = dwarf2_frame_get_fn_data (this_frame, this_cache, cookie);
1272+
gdb_assert (data == nullptr);
1273+
1274+
/* No object found, lets create a new instance. */
1275+
fn_data = FRAME_OBSTACK_ZALLOC (struct dwarf2_frame_fn_data);
1276+
fn_data->cookie = cookie;
1277+
fn_data->data = frame_obstack_zalloc (size);
1278+
fn_data->next = cache->fn_data;
1279+
cache->fn_data = fn_data;
1280+
1281+
return fn_data->data;
1282+
}
1283+
12241284
/* Proxy for tailcall_frame_dealloc_cache for bottom frame of a virtual tail
12251285
call frames chain. */
12261286

gdb/dwarf2/frame.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ enum dwarf2_frame_reg_rule
6666

6767
/* Register state. */
6868

69+
typedef struct value *(*fn_prev_register) (frame_info_ptr this_frame,
70+
void **this_cache, int regnum);
71+
6972
struct dwarf2_frame_state_reg
7073
{
7174
/* Each register save state can be described in terms of a CFA slot,
@@ -78,8 +81,7 @@ struct dwarf2_frame_state_reg
7881
const gdb_byte *start;
7982
ULONGEST len;
8083
} exp;
81-
struct value *(*fn) (frame_info_ptr this_frame, void **this_cache,
82-
int regnum);
84+
fn_prev_register fn;
8385
} loc;
8486
enum dwarf2_frame_reg_rule how;
8587
};
@@ -262,4 +264,35 @@ extern int dwarf2_fetch_cfa_info (struct gdbarch *gdbarch, CORE_ADDR pc,
262264
const gdb_byte **cfa_start_out,
263265
const gdb_byte **cfa_end_out);
264266

267+
268+
/* Allocate a new instance of the function unique data.
269+
270+
The main purpose of this custom function data object is to allow caching the
271+
value of expensive lookups in the prev_register implementation.
272+
273+
THIS_FRAME is the frame that the custom data object should be associated
274+
with.
275+
THIS_CACHE is the dwarf2 cache object to store the pointer on.
276+
COOKIE is the key for the prev_function implementation.
277+
SIZE is the size of the custom data object to allocate. */
278+
279+
extern void *dwarf2_frame_allocate_fn_data (frame_info_ptr this_frame,
280+
void **this_cache,
281+
fn_prev_register cookie,
282+
unsigned long size);
283+
284+
/* Retrieve the function unique data for this frame or NULL if none exists.
285+
286+
The main purpose of this custom function data object is to allow caching the
287+
value of expensive lookups in the prev_register implementation.
288+
289+
THIS_FRAME is the frame that the custom data object should be associated
290+
with.
291+
THIS_CACHE is the dwarf2 cache object to store the pointer on.
292+
COOKIE is the key for the prev_function implementation. */
293+
294+
extern void *dwarf2_frame_get_fn_data (frame_info_ptr this_frame,
295+
void **this_cache,
296+
fn_prev_register cookie);
297+
265298
#endif /* dwarf2-frame.h */

0 commit comments

Comments
 (0)