Skip to content

Commit 7587868

Browse files
authored
Merge pull request #28 from BinaryAnalysisPlatform/tcg-plugin
Handle edge cases in trace defintion if frames held less than `frames_per_toc_entry` frames
2 parents 7ac10c7 + e919a18 commit 7587868

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,42 @@
5151
make
5252
make install
5353
```
54+
55+
## Trace format
56+
57+
The trace consists of three parts: the header,
58+
a table of contents (TOC) holding the frames, and an index into the TOC.
59+
60+
A fixed number of frames are considered _one entry_ in the TOC.
61+
Frames in each entry starts with the size of the frame, followed by the actual frame data.
62+
Then the next frame size followed by the frame data and so forth.
63+
64+
The TOC index is stored at the end.
65+
66+
[!IMPORTANT]
67+
The last TOC entry might holds less than `m` frames.
68+
69+
For specifics about the frame contents, please check the definitions in the [piqi](piqi/) directory.
70+
71+
**Format**
72+
73+
| Offset | Type | Field | Note |
74+
|--------|------|-------|------|
75+
| 0x0 | uint64_t | magic number (7456879624156307493LL) | Header begin |
76+
| 0x8 | uint64_t | trace version number | |
77+
| 0x10 | uint64_t | frame_architecture | |
78+
| 0x18 | uint64_t | frame_machine, 0 for unspecified. | |
79+
| 0x20 | uint64_t | n = total number of frames in trace. | |
80+
| 0x28 | uint64_t | T = offset to TOC index. | |
81+
| 0x30 | uint64_t | sizeof(frame_0) | TOC begin |
82+
| 0x38 | meta_frame | frame_0 | |
83+
| 0x40 | uint64_t | sizeof(frame_1) | |
84+
| 0x48 | type(frame_1) | frame_1 | |
85+
| ... | ... | ... | |
86+
| T-0x10 | uint64_t | sizeof(frame_n-1) | |
87+
| T-0x8 | type(frame_n-1) | frame_n-1 | |
88+
| T+0 | uint64_t | m = maximum number of frames per TOC entry | TOC index begin |
89+
| T+0x8 | uint64_t | offset toc_entry(0) | |
90+
| T+0x10 | uint64_t | offset toc_entry(1) | |
91+
| ... | ... | ... | |
92+
| T+0x8+(0x8*ceil(n/m)) | uint64_t | offset toc_entry(ceil(n/m)) | |

libtrace/src/frame_arch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,6 @@ enum frame_architecture
435435
#define FRAME_MODE_PPC32 "ppc:ppc"
436436
#define FRAME_MODE_PPC64 "ppc:ppc64"
437437

438+
#define FRAME_MODE_NONE NULL
439+
438440
#endif

libtrace/src/trace.container.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ namespace SerializedTrace {
149149
/* Read number of frames per toc entry. */
150150
READ(frames_per_toc_entry);
151151

152+
size_t add = (num_frames % frames_per_toc_entry != 0) ? 1 : 0;
152153
/* Read each toc entry. */
153-
for (int i = 0; i < ((num_frames - 1) / frames_per_toc_entry); i++) {
154+
for (int i = 0; i < (num_frames / frames_per_toc_entry) + add; i++) {
154155
uint64_t offset;
155156
READ(offset);
156157
toc.push_back(offset);

0 commit comments

Comments
 (0)