How to run through the BBL

36 views
Skip to first unread message

Arthur

unread,
Dec 27, 2021, 12:32:56 PM12/27/21
to dynamor...@googlegroups.com
I would like to run through the Basic block

for i ; i++ {
  being i each instruction ?
}

sharma...@google.com

unread,
Dec 28, 2021, 3:16:28 PM12/28/21
to DynamoRIO Users
Hi,
The drmgr extension (https://dynamorio.org/page_drmgr.html#sec_drmgr_stages) offers various event callbacks where you can iterate through basic blocks. Depending on your use case, you can choose from any of these:
1. If you want to only analyse the basic blocks, but not add any instrumentation, use the analysis callback which is invoked for each basic block, and gets the instrlist_t (the instruction list with all instructions) for the fragment. E.g.  https://github.com/DynamoRIO/dynamorio/blob/27193828261be587d06bcbbca3eabc49726d441f/api/samples/inscount.cpp#L143. This sample also shows a for-loop that can iterate through all instructions in an instrlist_t.
2. If you want to add your own instrumentation to the basic block, use the drmgr insertion callback, which is invoked separately for each instruction in the fragment: https://github.com/DynamoRIO/dynamorio/blob/27193828261be587d06bcbbca3eabc49726d441f/api/samples/countcalls.c#L222
3. If you want to do app to app transformations, use the drmgr app2app callback, which is invoked for each basic block: https://github.com/DynamoRIO/dynamorio/blob/27193828261be587d06bcbbca3eabc49726d441f/api/samples/prefetch.c#L91

You can register your event callbacks using routines like drmgr_register_bb_instrumentation_eventdrmgr_register_bb_app2app_event etc

Abhinav

Arthur

unread,
Dec 28, 2021, 4:06:44 PM12/28/21
to dynamor...@googlegroups.com
I've read most of the examples, https://dynamorio.org/page_drmgr.html#sec_drmgr_stages) , I will be reading this. but haven't found so far something exactly like I needed

I wanted something similar to this:

for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl))

but I'm not sure if the dr trace event would be able.: dr_register_trace_event



--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dynamorio-users/4ad81164-a1ea-4993-be25-7caaec8e6f23n%40googlegroups.com.

Abhinav Sharma

unread,
Dec 28, 2021, 7:46:30 PM12/28/21
to dynamor...@googlegroups.com
Hi,
Can you clarify whether you want to iterate over instructions or basic blocks in a trace?

You can iterate over the instructions in a trace using the for-loop like https://github.com/DynamoRIO/dynamorio/blob/27193828261be587d06bcbbca3eabc49726d441f/api/samples/inscount.cpp#L173. Also, the drmgr_register_bb_instrumentation_event, drmgr_register_bb_app2app_event etc callbacks have a 'for_trace` boolean argument that tells whether the given instr_t or instrlist_t is for a trace fragment. 

But as far as I know, there's no API that allows iterating over the basic blocks that make up a fragment. Would looking at instr_get_app_pc for the individual instructions help? (Basic block tags are basically their app PCs). Maybe more details about your use case will help.

Abhinav

Arthur

unread,
Dec 28, 2021, 7:51:18 PM12/28/21
to dynamor...@googlegroups.com
I want to iterate over the trace,
Go from one BB to the next one.

While in the BB i will use the common iterarion that exists.

Reply all
Reply to author
Forward
0 new messages