1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
13 mEntries
.mNext
= static_cast<EntryBlock
*>(&mEntries
);
14 mEntries
.mPrev
= static_cast<EntryBlock
*>(&mEntries
);
19 for (const_iterator entry
= begin(), entry_end
= end();
20 entry
!= entry_end
; ++entry
) {
21 free((void*) (*entry
)->type
);
22 free((char*) (*entry
)->data
);
23 free((char*) (*entry
)->allocation_stack
);
26 for (EntryBlock
*b
= mEntries
.mNext
, *next
; b
!= &mEntries
; b
= next
) {
33 ADLog::Read(const char* aFileName
)
35 FILE *in
= fopen(aFileName
, "r");
44 int res
= fscanf(in
, "%x %s (%d)\n", &ptr
, typebuf
, &datasize
);
51 size_t data_mem_size
= ((datasize
+ sizeof(unsigned long) - 1) /
52 sizeof(unsigned long)) * sizeof(unsigned long);
53 char *data
= (char*)malloc(data_mem_size
);
55 for (unsigned long *cur_data
= (unsigned long*) data
,
56 *cur_data_end
= (unsigned long*) ((char*)data
+ data_mem_size
);
57 cur_data
!= cur_data_end
; ++cur_data
) {
58 res
= fscanf(in
, " %lX\n", cur_data
);
64 char stackbuf
[100000];
67 char *stack
= stackbuf
;
70 fgets(stack
, sizeof(stackbuf
) - (stack
- stackbuf
), in
);
75 if (mEntryCount
% ADLOG_ENTRY_BLOCK_SIZE
== 0) {
76 EntryBlock
*new_block
= new EntryBlock();
77 new_block
->mNext
= static_cast<EntryBlock
*>(&mEntries
);
78 new_block
->mPrev
= mEntries
.mPrev
;
79 mEntries
.mPrev
->mNext
= new_block
;
80 mEntries
.mPrev
= new_block
;
83 size_t typelen
= strlen(typebuf
);
84 char *type
= (char*)malloc(typelen
-1);
85 strncpy(type
, typebuf
+1, typelen
-2);
86 type
[typelen
-2] = '\0';
89 &mEntries
.mPrev
->entries
[mEntryCount
% ADLOG_ENTRY_BLOCK_SIZE
];
90 entry
->address
= (Pointer
)ptr
;
92 entry
->datasize
= datasize
;
94 entry
->allocation_stack
= strdup(stackbuf
);
102 ADLog::const_iterator::const_iterator(ADLog::EntryBlock
*aBlock
,
106 mCur
= mBlockStart
+ aOffset
;
109 ADLog::const_iterator
&
110 ADLog::const_iterator::operator++()
113 if (mCur
== mBlockEnd
) {
114 SetBlock(mBlock
->mNext
);
121 ADLog::const_iterator
&
122 ADLog::const_iterator::operator--()
124 if (mCur
== mBlockStart
) {
125 SetBlock(mBlock
->mPrev
);