From dcfb3eb1e646be78dca8c5b7317edc65d7785bce Mon Sep 17 00:00:00 2001 From: Ketan Dixit Date: Fri, 13 Aug 2010 18:30:29 -0400 Subject: [PATCH] Capturing line no and file name of a joinpoint --- src/aop-pc-assign.c | 4 +++- src/aop-pc-entry.c | 19 +++++++++++++++++-- src/aop-pc-exit.c | 4 +++- src/aop-pc-fun-call.c | 14 ++++++++------ src/aop-pointcut.c | 18 +++++++++++++++++- src/aop-pointcut.h | 10 +++++++--- src/aop.h | 4 ++++ 7 files changed, 59 insertions(+), 14 deletions(-) diff --git a/src/aop-pc-assign.c b/src/aop-pc-assign.c index 07b88b8..03801cf 100644 --- a/src/aop-pc-assign.c +++ b/src/aop-pc-assign.c @@ -306,6 +306,7 @@ op_join_on_assign (struct aop_pointcut *pc, join_callback cb, void *callback_param) { basic_block bb; + expanded_location xloc; aop_assert (pc->kind == ATP_ASSIGN); @@ -320,7 +321,8 @@ op_join_on_assign (struct aop_pointcut *pc, join_callback cb, if (stmt_matches_pointcut (pc, stmt)) { struct aop_joinpoint jp; - init_joinpoint (&jp, &gsi, pc, stmt); + xloc = expand_location (gimple_location (stmt)); + init_joinpoint (&jp, &gsi, pc, stmt, xloc.line, xloc.file); cb (&jp, callback_param); } } diff --git a/src/aop-pc-entry.c b/src/aop-pc-entry.c index 33c985b..faf7ee8 100644 --- a/src/aop-pc-entry.c +++ b/src/aop-pc-entry.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "aop.h" #include "aop-pointcut.h" @@ -42,12 +43,26 @@ * \{ */ +static expanded_location +get_function_entry_xloc() +{ + basic_block bb; + expanded_location xloc; + + bb = ENTRY_BLOCK_PTR_FOR_FUNCTION (cfun); + xloc = expand_location (gimple_location (first_stmt (bb->next_bb))); + return xloc; +} + + + static void op_join_on_function_entry (struct aop_pointcut *pc, join_callback cb, void *callback_param) { struct aop_joinpoint jp; gimple_stmt_iterator gsi; + expanded_location xloc; aop_assert (pc->kind == ATP_ENTRY); @@ -64,8 +79,8 @@ op_join_on_function_entry (struct aop_pointcut *pc, join_callback cb, op_prepare_entry when it is time to insert advice. (We poison it just to make sure that initialization is getting called.)*/ memset (&gsi, 0xfa, sizeof (gimple_stmt_iterator)); - - init_joinpoint (&jp, &gsi, pc, NULL); + xloc = get_function_entry_xloc (); + init_joinpoint (&jp, &gsi, pc, NULL, xloc.line, xloc.file); cb (&jp, callback_param); } diff --git a/src/aop-pc-exit.c b/src/aop-pc-exit.c index ca31b76..cf1caf0 100644 --- a/src/aop-pc-exit.c +++ b/src/aop-pc-exit.c @@ -48,6 +48,7 @@ op_join_on_function_exit (struct aop_pointcut *pc, join_callback cb, { basic_block bb; gimple stmt; + expanded_location xloc; aop_assert (pc->kind == ATP_EXIT); FOR_EACH_BB(bb) @@ -60,7 +61,8 @@ op_join_on_function_exit (struct aop_pointcut *pc, join_callback cb, if (gimple_code (stmt) == GIMPLE_RETURN) { struct aop_joinpoint jp; - init_joinpoint (&jp, &gsi, pc, stmt); + xloc = expand_location (gimple_location (stmt)); + init_joinpoint (&jp, &gsi, pc, stmt, xloc.line, xloc.file); cb (&jp, callback_param); /* It's possible that gsi is no longer a valid iterator diff --git a/src/aop-pc-fun-call.c b/src/aop-pc-fun-call.c index 5cc0da0..7293ab7 100644 --- a/src/aop-pc-fun-call.c +++ b/src/aop-pc-fun-call.c @@ -136,13 +136,14 @@ op_join_on_function_call (struct aop_pointcut *pc, join_callback cb, { basic_block my_basic_block; gimple_stmt_iterator gsi; + expanded_location xloc; aop_assert (pc->kind == ATP_CALL); FOR_EACH_BB(my_basic_block) { for (gsi = gsi_start_bb (my_basic_block) ; !gsi_end_p (gsi) ; - gsi_next (&gsi)) + gsi_next (&gsi)) { gimple stmt = gsi_stmt (gsi); @@ -155,7 +156,8 @@ op_join_on_function_call (struct aop_pointcut *pc, join_callback cb, if (call_matches (pc, stmt)) { struct aop_joinpoint jp; - init_joinpoint (&jp, &gsi, pc, stmt); + xloc = expand_location (gimple_location (stmt)); + init_joinpoint (&jp, &gsi, pc, stmt, xloc.line, xloc.file); cb (&jp, callback_param); } } @@ -256,7 +258,7 @@ op_get_return_value (struct aop_dynval *dv) struct aop_joinpoint *jp = dv->jp; stmt = gsi_stmt (*(jp->gsi)); - + /* If this function isn't on the right side of an assignment, we need to _put it_ on the right hand side of an assignment so we can grab its return value. */ @@ -265,7 +267,7 @@ op_get_return_value (struct aop_dynval *dv) tree new_lhs = create_tmp_var (gimple_call_return_type(stmt), "aop_return"); gimple_call_set_lhs (stmt, new_lhs); - update_stmt (stmt); + update_stmt (stmt); } return_value = stabilize_reference (gimple_call_lhs (stmt)); @@ -347,7 +349,7 @@ aop_capture_return_value (struct aop_joinpoint *jp) dv->type = pc->pc_call.return_type; dv->jp = jp; dv->get_dynval = op_get_return_value; - return dv; + return dv; } /** @@ -386,7 +388,7 @@ aop_capture_return_value_by_type (struct aop_joinpoint *jp, dv->type = type; dv->jp = jp; dv->get_dynval = op_get_return_value; - return dv; + return dv; } static tree diff --git a/src/aop-pointcut.c b/src/aop-pointcut.c index 587b097..4c4727f 100644 --- a/src/aop-pointcut.c +++ b/src/aop-pointcut.c @@ -54,10 +54,26 @@ create_pointcut (enum aop_pckind kind) /* Initializes a joinpoint with default values. */ void init_joinpoint (struct aop_joinpoint *jp, gimple_stmt_iterator *gsi, - struct aop_pointcut *pc, gimple stmt) + struct aop_pointcut *pc, gimple stmt, int line, + const char *file) { jp->pc = pc; jp->gsi = gsi; jp->stmt = stmt; + jp->line = line; + jp->file = file; jp->is_prepared = false; + +} + +int +aop_capture_lineno (struct aop_joinpoint *jp) +{ + return jp->line; +} + +const char * +aop_capture_file_name (struct aop_joinpoint *jp) +{ + return jp->file; } diff --git a/src/aop-pointcut.h b/src/aop-pointcut.h index 6c6ff8c..7f6a338 100644 --- a/src/aop-pointcut.h +++ b/src/aop-pointcut.h @@ -55,7 +55,7 @@ struct aop_pc_entry { struct aop_pc_fun_call { const char *function_name; const struct aop_type *return_type; - struct aop_param_desc *param_list_head; + struct aop_param_desc *param_list_head; }; /* An AOP pointcut represents the a set of joinponts: locations in the @@ -70,7 +70,6 @@ struct aop_pointcut { void (*join_on) (struct aop_pointcut *, join_callback, void *); insert_callback insert_before; insert_callback insert_after; - /* prepare_for_weave() gets called once for each joinpoint before any advice gets inserted at that joinpoint. */ @@ -104,12 +103,17 @@ struct aop_joinpoint { /* True if prepare_for_weave() has been called for this joinpoint. */ bool is_prepared; + /* The line number corresponding to the joinpoint */ + int line; + /* The file name corresponding to the joinpoint */ + const char *file; }; struct aop_pointcut *create_pointcut (enum aop_pckind kind); void init_joinpoint (struct aop_joinpoint *jp, gimple_stmt_iterator *gsi, - struct aop_pointcut *pc, gimple stmt); + struct aop_pointcut *pc, gimple stmt, int line, + const char *file); void op_default_prepare_for_weave (struct aop_joinpoint *jp); void op_default_insert_before (struct aop_joinpoint *jp, gimple stmt); diff --git a/src/aop.h b/src/aop.h index 9e9b607..0571498 100644 --- a/src/aop.h +++ b/src/aop.h @@ -299,4 +299,8 @@ extern struct aop_dynval *aop_capture_assigned_value (struct aop_joinpoint *jp); */ extern int aop_capture_lhs_var_scope (struct aop_joinpoint *jp); + +extern int aop_capture_lineno (struct aop_joinpoint *jp); + +extern const char *aop_capture_file_name (struct aop_joinpoint *jp); #endif -- 2.43.0