Skip to content

Commit 1d80945

Browse files
authored
adds support for frame-local (cpu) modes (#17)
* adds support for frame-local (cpu) modes This adds a new field `mode` to std frames, which corresponds to Bap_trace_event_types.Mode, expressing for example whether the frame's instruction was run in thumb mode or not. While protobuf does maintain compatibility after adding fields, piqi does not seem to explicitly make such an assertion. Thus, the format version has been bumped to 3, to at least indicate the change. Broken support for writing v1 traces has also been removed from C++ libtrace. * catches unknown mode values
1 parent b749b8b commit 1d80945

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

lib/frame_events.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ module EF : sig
4848
val modload : arch option ->
4949
string -> Frame.address -> Frame.address -> Trace.event
5050

51+
val mode : string -> Trace.event
52+
5153
(* val call : ??? *)
5254
(* val return : ??? *)
5355
end = struct
@@ -114,6 +116,9 @@ end = struct
114116
~low:(addr_of_address arch low)
115117
~high:(addr_of_address arch high) |>
116118
Value.create modload
119+
120+
let mode (fe : string) =
121+
Value.create mode (try Mode.read fe with _exn -> Mode.unknown)
117122
end
118123

119124
let of_new_frame context arch address thread_id =
@@ -152,9 +157,12 @@ let of_operand_info arch oi =
152157
let of_operand_value_list arch ovl =
153158
List.concat @@ List.map ~f:(of_operand_info arch) ovl
154159

160+
let of_mode mode = [EF.mode mode]
161+
155162
let of_std_frame context arch frm =
156163
let open Frame.Std_frame in
157164
List.concat [of_new_frame context arch frm.address frm.thread_id;
165+
Option.value_map frm.mode ~default:[] ~f:(of_mode);
158166
[EF.code_exec arch frm.address frm.rawbytes];
159167
of_operand_value_list arch frm.operand_pre_list;
160168
Option.value_map frm.operand_post_list ~default:[]

libtrace/src/copytrace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main(int argc, char **argv) {
2525
std::string dstfile(argv[2]);
2626

2727
TraceContainerReader r(srcfile);
28-
TraceContainerWriter w(dstfile, r.get_arch(), r.get_machine(), r.get_frames_per_toc_entry());
28+
TraceContainerWriter w(dstfile, *r.get_meta(), r.get_arch(), r.get_machine(), r.get_frames_per_toc_entry());
2929

3030
copy_all(r, w);
3131
w.finish();

libtrace/src/frame_arch.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,11 @@ enum frame_architecture
387387
frame_arch_last
388388
};
389389

390+
/**
391+
* Optional per-frame information indicating execution in a specific (CPU) mode.
392+
* These are the string representations of possible Bap_traces.Mode.t values.
393+
*/
394+
#define FRAME_MODE_ARM_A32 "arm:a32"
395+
#define FRAME_MODE_ARM_T32 "arm:t32"
396+
390397
#endif

libtrace/src/trace.container.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,14 @@ namespace SerializedTrace {
4141
return ofs;
4242
}
4343

44-
45-
TraceContainerWriter::TraceContainerWriter(const std::string& filename,
46-
frame_architecture arch,
47-
uint64_t machine,
48-
uint64_t frames_per_toc_entry_in)
49-
: num_frames (0)
50-
, frames_per_toc_entry (frames_per_toc_entry_in)
51-
, ofs(open_trace(filename,arch,machine,1LL)) {}
52-
5344
TraceContainerWriter::TraceContainerWriter(const std::string& filename,
5445
const meta_frame& meta,
5546
frame_architecture arch,
5647
uint64_t machine,
5748
uint64_t frames_per_toc_entry_in)
5849
: num_frames (0)
5950
, frames_per_toc_entry (frames_per_toc_entry_in)
60-
, ofs(open_trace(filename,arch,machine,2LL)) {
51+
, ofs(open_trace(filename,arch,machine,3LL)) {
6152
std::string meta_data;
6253
if (!(meta.SerializeToString(&meta_data))) {
6354
throw TraceException("Unable to serialize meta frame to ostream");

libtrace/src/trace.container.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace SerializedTrace {
6767
const uint64_t meta_offset = 56LL;
6868

6969
const uint64_t lowest_supported_version = 2LL;
70-
const uint64_t highest_supported_version = 2LL;
70+
const uint64_t highest_supported_version = 3LL;
7171

7272

7373
class TraceException: public std::exception
@@ -97,12 +97,6 @@ namespace SerializedTrace {
9797
/** Creates a trace container writer that will output to
9898
[filename]. An entry will be added to the table of contents
9999
every [frames_per_toc_entry] entries.*/
100-
TraceContainerWriter(const std::string& filename,
101-
frame_architecture arch = default_arch,
102-
uint64_t machine = default_machine,
103-
uint64_t frames_per_toc_entry = default_frames_per_toc_entry);
104-
105-
// creates a container for the second version of a protocol.
106100
TraceContainerWriter(const std::string& filename,
107101
const meta_frame& meta,
108102
frame_architecture arch = default_arch,

piqi/stdframe.piqi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@
3939
.code 5
4040
.optional
4141
]
42+
43+
% Per-frame (CPU) mode, for example for indicating thumb mode in Arm
44+
.field [
45+
.name mode
46+
.type string
47+
.code 6
48+
.optional
49+
]
4250
]

0 commit comments

Comments
 (0)