Mercurial > libpst
changeset 203:9fb600ef4e03
cleanup debug logging
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 19 May 2009 10:20:33 -0700 |
parents | 2f38c4ce606f |
children | 268458c79e9b |
files | regression/regression-tests.bash src/libpst.c src/readpst.c src/readpstlog.c src/testdebug.c |
diffstat | 5 files changed, 32 insertions(+), 297 deletions(-) [+] |
line wrap: on
line diff
--- a/regression/regression-tests.bash Mon May 18 15:55:05 2009 -0700 +++ b/regression/regression-tests.bash Tue May 19 10:20:33 2009 -0700 @@ -56,7 +56,6 @@ #val ../src/readpst $jobs -r -D -cv -o output$n $fn $val ../src/readpst $jobs -r -D -cv -o output$n -d $ba.log $fn >$ba.err 2>&1 #../src/getidblock -p $fn 0 >$ba.fulldump - #rm -f dumper }
--- a/src/libpst.c Mon May 18 15:55:05 2009 -0700 +++ b/src/libpst.c Tue May 19 10:20:33 2009 -0700 @@ -1220,7 +1220,7 @@ if (d_ptr->assoc_tree) { if (m_head) { - DEBUG_WARN(("supplied master head, but have a list that is building a new id2_head")); + DEBUG_WARN(("supplied master head, but have a list that is building a new id2_head\n")); m_head = NULL; } id2_head = pst_build_id2(pf, d_ptr->assoc_tree); @@ -1395,10 +1395,10 @@ pst_block_offset_pointer block_offset6; pst_block_offset_pointer block_offset7; int32_t x; - int num_recs; - int count_rec; - int32_t num_list; - int32_t cur_list; + int32_t num_mapi_objects; + int32_t count_mapi_objects; + int32_t num_mapi_elements; + int32_t count_mapi_elements; int block_type; uint32_t rec_size = 0; char* list_start; @@ -1529,8 +1529,8 @@ } list_start = block_offset2.from; to_ptr = block_offset2.to; - num_list = (to_ptr - list_start)/sizeof(table_rec); - num_recs = 1; // only going to be one object in these blocks + num_mapi_elements = (to_ptr - list_start)/sizeof(table_rec); + num_mapi_objects = 1; // only going to be one object in these blocks } else if (block_hdr.type == (uint16_t)0x7CEC) { //type 2 block_type = 2; @@ -1563,7 +1563,7 @@ } rec_size = seven_c_blk.rec_size; - num_list = (int32_t)(unsigned)seven_c_blk.item_count; + num_mapi_elements = (int32_t)(unsigned)seven_c_blk.item_count; if (pst_getBlockOffsetPointer(pf, i2_head, &subblocks, seven_c_blk.b_five_offset, &block_offset4)) { DEBUG_WARN(("internal error (7c.b5 offset %#x) in reading block id %#"PRIx64"\n", seven_c_blk.b_five_offset, block_id)); @@ -1592,7 +1592,7 @@ } // this will give the number of records in this block - num_recs = (block_offset5.to - block_offset5.from) / (4 + table_rec.ref_type); + num_mapi_objects = (block_offset5.to - block_offset5.from) / (4 + table_rec.ref_type); if (pst_getBlockOffsetPointer(pf, i2_head, &subblocks, seven_c_blk.ind2_offset, &block_offset6)) { DEBUG_WARN(("internal error (7c.ind2 offset %#x) in reading block id %#"PRIx64"\n", seven_c_blk.ind2_offset, block_id)); @@ -1602,6 +1602,7 @@ } ind2_ptr = block_offset6.from; ind2_end = block_offset6.to; + DEBUG_INFO(("7cec block index2 pointer %#x and end %#x\n", ind2_ptr, ind2_end)); } else { DEBUG_WARN(("ERROR: Unknown block constant - %#hx for id %#"PRIx64"\n", block_hdr.type, block_id)); @@ -1610,24 +1611,25 @@ return NULL; } - DEBUG_INFO(("Mallocing number of records %i\n", num_recs)); - for (count_rec=0; count_rec<num_recs; count_rec++) { + DEBUG_INFO(("found %i mapi objects each with %i mapi elements\n", num_mapi_objects, num_mapi_elements)); + for (count_mapi_objects=0; count_mapi_objects<num_mapi_objects; count_mapi_objects++) { + // put another mapi object on the linked list mo_ptr = (pst_mapi_object*) pst_malloc(sizeof(pst_mapi_object)); memset(mo_ptr, 0, sizeof(pst_mapi_object)); mo_ptr->next = mo_head; mo_head = mo_ptr; - // allocate an array of count num_recs to contain sizeof(pst_mapi_element) - mo_ptr->elements = (pst_mapi_element**) pst_malloc(sizeof(pst_mapi_element)*num_list); - mo_ptr->count_elements = num_list; - mo_ptr->orig_count = num_list; - mo_ptr->count_objects = (int32_t)num_recs; // each record will have a record of the total number of records - for (x=0; x<num_list; x++) mo_ptr->elements[x] = NULL; - x = 0; - - DEBUG_INFO(("going to read %i (%#x) items\n", mo_ptr->count_elements, mo_ptr->count_elements)); - - fr_ptr = list_start; // initialize fr_ptr to the start of the list. - for (cur_list=0; cur_list<num_list; cur_list++) { //we will increase fr_ptr as we progress through index + // allocate the array of mapi elements + mo_ptr->elements = (pst_mapi_element**) pst_malloc(sizeof(pst_mapi_element)*num_mapi_elements); + mo_ptr->count_elements = num_mapi_elements; + mo_ptr->orig_count = num_mapi_elements; + mo_ptr->count_objects = (int32_t)num_mapi_objects; // each record will have a record of the total number of records + for (x=0; x<num_mapi_elements; x++) mo_ptr->elements[x] = NULL; + + DEBUG_INFO(("going to read %i mapi elements for mapi object %i\n", num_mapi_elements, count_mapi_objects)); + + fr_ptr = list_start; // initialize fr_ptr to the start of the list. + x = 0; // x almost tracks count_mapi_elements, but see 'continue' statement below + for (count_mapi_elements=0; count_mapi_elements<num_mapi_elements; count_mapi_elements++) { //we will increase fr_ptr as we progress through index char* value_pointer = NULL; // needed for block type 2 with values larger than 4 bytes size_t value_size = 0; if (block_type == 1) { @@ -1642,6 +1644,8 @@ LE16_CPU(table2_rec.ref_type); LE16_CPU(table2_rec.type); LE16_CPU(table2_rec.ind2_off); + DEBUG_INFO(("reading element %i (type=%#x, ref_type=%#x, offset=%#x, size=%#x)\n", + x, table2_rec.type, table2_rec.ref_type, table2_rec.ind2_off, table2_rec.size)); // table_rec and table2_rec are arranged differently, so assign the values across table_rec.type = table2_rec.type; @@ -1671,7 +1675,7 @@ DEBUG_RET(); return NULL; } - DEBUG_INFO(("reading block %i (type=%#x, ref_type=%#x, value=%#x)\n", + DEBUG_INFO(("reading element %i (type=%#x, ref_type=%#x, value=%#x)\n", x, table_rec.type, table_rec.ref_type, table_rec.value)); if (!mo_ptr->elements[x]) { @@ -2531,7 +2535,7 @@ LIST_COPY_FOLDER_INT32("Associated Content count", item->folder->assoc_count); break; case 0x3701: // PR_ATTACH_DATA_OBJ binary data of attachment - DEBUG_INFO(("Binary Data [Size %i] - ", list->elements[x]->size)); + DEBUG_INFO(("Binary Data [Size %i]\n", list->elements[x]->size)); NULL_CHECK(attach); if (!list->elements[x]->data) { //special case attach->id2_val = list->elements[x]->type; @@ -2825,13 +2829,12 @@ DEBUG_HEXDUMP(item->predecessor_change.data, item->predecessor_change.size); break; case 0x67F2: // ID2 value of the attachments proper record - DEBUG_INFO(("Attachment ID2 value - ")); if (attach) { uint32_t tempid; memcpy(&(tempid), list->elements[x]->data, sizeof(tempid)); LE32_CPU(tempid); attach->id2_val = tempid; - DEBUG_INFO(("%#"PRIx64"\n", attach->id2_val)); + DEBUG_INFO(("Attachment ID2 value - %#"PRIx64"\n", attach->id2_val)); } else { DEBUG_WARN(("NOT AN ATTACHMENT: %#x\n", list->elements[x]->mapi_id)); } @@ -3572,7 +3575,7 @@ LE16_CPU(p->to); DEBUG_WARN(("get block offset finds from=%i(%#x), to=%i(%#x)\n", p->from, p->from, p->to, p->to)); if (p->from > p->to) { - DEBUG_WARN(("get block offset from > to")); + DEBUG_WARN(("get block offset from > to\n")); DEBUG_RET(); return 0; }
--- a/src/readpst.c Mon May 18 15:55:05 2009 -0700 +++ b/src/readpst.c Tue May 19 10:20:33 2009 -0700 @@ -1085,7 +1085,7 @@ DEBUG_INFO(("charset %s from html text\n", charset)); } else { - DEBUG_INFO(("matching %d %d %d %d", match[0].rm_so, match[0].rm_eo, match[1].rm_so, match[1].rm_eo)); + DEBUG_INFO(("matching %d %d %d %d\n", match[0].rm_so, match[0].rm_eo, match[1].rm_so, match[1].rm_eo)); DEBUG_HEXDUMPC(html, strlen(html), 0x10); } }
--- a/src/readpstlog.c Mon May 18 15:55:05 2009 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,245 +0,0 @@ - -#include "define.h" - -#define BUF_SIZE 4096 - -void usage(); -size_t get(void * buf, int size, unsigned int count, FILE *fp); -int split_args(char *args, int **targ); -int is_in(int a, int *b, int c); - -int main(int argc, char* const* argv) { - int identity = 0; - int level = 0; - int x, ptr, stop=0, flag; - char *fname, *buf, rec_type; - unsigned char version; - int *show_type=NULL, show_size=0; - int *ex_type=NULL, ex_size=0; - unsigned int funcname=0, filename=0, text=0, end=0, dtype=0, line=0; - int c; - char ch; - FILE *fp; - struct pst_debug_file_rec_m mfile_rec; - struct pst_debug_file_rec_l lfile_rec; - char format = 'D'; // default - while ((c = getopt(argc, argv, "f:t:x:")) != -1) { - ch = c; - switch(ch) { - case 'f': - // change the output format - format = toupper(optarg[0]); - break; - case 't': - //change the type of statements shown - show_size = split_args(optarg, &show_type); - // type = atoi(optarg); - break; - case 'x': - // change the type of statements excluded - ex_size = split_args(optarg, &ex_type); - break; - } - } - if (argc > optind) { - fname = argv[optind++]; - } else { - usage(); - exit(2); - } - - fp = fopen(fname, "rb"); - if (fp == NULL) { - printf("Error. couldn't open debug file\n"); - return 2; - } - if (get(&version, sizeof(char), 1, fp)==0) { - printf("Error. could not read version byte from front of file"); - return 3; - } - - if (version > DEBUG_VERSION) { - printf("Version number is higher than the format I know about."); - return 4; - } - - buf = (char*) pst_malloc(BUF_SIZE); - - while (!stop) { - int64_t temp; - if (fread(&temp, sizeof(int64_t), 1, fp)<=0) break; - x = (int)temp; - ptr = 0; - if (x > 0) { - int64_t i[x+1]; // plus 1 because we want to read the offset of the next index - if (get(i, sizeof(int64_t), x+1, fp)==0) { - // we have reached the end of the debug file - printf("oh dear. we must now end\n"); - break; - } - while (ptr < x) { - fseeko(fp, i[ptr++], SEEK_SET); - get(&rec_type, 1, sizeof(char), fp); - if (rec_type == 'L') { - get(&lfile_rec, sizeof(lfile_rec), 1, fp); - funcname=lfile_rec.funcname; - filename=lfile_rec.filename; - text = lfile_rec.text; - end = lfile_rec.end; - dtype = lfile_rec.type; - line = lfile_rec.line; - } else if (rec_type == 'M') { - get(&mfile_rec, sizeof(mfile_rec), 1, fp); - funcname = mfile_rec.funcname; - filename = mfile_rec.filename; - text = mfile_rec.text; - end = mfile_rec.end; - dtype = mfile_rec.type; - line = mfile_rec.line; - } - if (dtype == DEBUG_FUNCENT_NO) level++; - if ((show_type == NULL || is_in(dtype, show_type, show_size)) && - (ex_type == NULL || !is_in(dtype, ex_type, ex_size))) { - unsigned int c = 0; - flag = 0; - while (c < end) { - int ii = (level-1) * 4; - if (ii < 0) ii = 0; - if (ii > 64) ii = 64; - char indent[ii+1]; - memset(indent, ' ', ii); - indent[ii] = '\0'; - if (c + (BUF_SIZE-1) < end) { - get(buf, 1, BUF_SIZE-1, fp); - buf[BUF_SIZE-1] = '\0'; - c += BUF_SIZE-1; - } else { - get(buf, 1, end-c, fp); - buf[end-c] = '\0'; - c = end; - } - if (flag == 0) { - if (format == 'I') { // indented text format - char *b = buf+text; - identity++; - //printf("%s %d %s/%s[%d]: ", indent, identity, &buf[filename], &buf[funcname], line); - printf("%s %s/%s[%d]: ", indent, &buf[filename], &buf[funcname], line); - while (b) { - char *p = strchr(b, '\n'); - if (p) { - *p = '\0'; - printf("%s\n%s ", b, indent); - b = p + 1; - } - else { - printf("%s", b); - b = NULL; - } - } - } - else if (format == 'T') { // text format - printf("%s/%s[%d]: %s", &buf[filename], &buf[funcname], line, &buf[text]); - } else { - printf("Type: %d\nFile[line]: %s[%d]\nFunction:%s\nText:%s", dtype, - &buf[filename], line, &buf[funcname], &buf[text]); - } - flag = 1; - } else { - if (format == 'I') { - char *b = buf; - while (b) { - char *p = strchr(b, '\n'); - if (p) { - *p = '\0'; - printf("%s\n%s ", b, indent); - b = p + 1; - } - else { - printf("%s", b); - b = NULL; - } - } - } - else printf("%s", buf); - } - } - printf("\n"); - } - if (dtype == DEBUG_FUNCRET_NO) level--; - } - if (fseeko(fp, i[ptr], SEEK_SET)==-1) { - printf("finished\n"); - break; - } - } else { - printf("...no more items\n"); - break; - } - } - free(buf); - fclose(fp); - if (format == 'I') printf("final indent level = %i\n", level); - return 0; -} - -size_t get(void *buf, int size, unsigned int count, FILE *fp) { - size_t z; - if ((z=fread(buf, size, count, fp)) < count) { - printf("Read Failed! (size=%d, count=%d,z=%ld)\n", size, count, (long)z); - exit(1); - } - return z; -} - -void usage() { - printf("readlog -t[show_type] -x[exclude_type] -f[format] filename\n"); - printf("\tformat:\n\t\tt: text log format\n"); - printf("\t\ti: indented text log format\n"); - printf("\tshow_type:\n\t\tcomma separated list of types to show " - "[ie, 2,4,1,6]\n"); - printf("\texclude_type:\n\t\tcomma separated list of types to exclude " - "[ie, 1,5,3,7]\n"); -} - - -int split_args(char *args, int **targ) { - int count = 1, *i, x, z; - char *tmp = args, *y; - if (*targ != NULL) { - free(*targ); - } - // find the number of tokens in the string. Starting - // from 1 cause there will always be one - while ((tmp = strchr(tmp, ',')) != NULL) { - tmp++; count++; - } - *targ = (int*)pst_malloc(count * sizeof(int)); - i = *targ; // for convienience - tmp = args; - z = 0; - for (x = 0; x < count; x++) { - y = strtok(tmp, ","); - tmp = NULL; // must be done after first call - if (y != NULL) { - i[x] = atoi(y); - z++; - } - } - return z; -} - - -// checks to see if the first arg is in the array of the second arg, -// the size of which is specified with the third arg. If the second -// arg is NULL, then it is obvious that it is not there. -int is_in(int a, int *b, int c){ - int d = 0; - if (b == NULL || c == 0) { // no array or no items in array - return 0; - } - while (d < c) { - if (a == b[d]) return 1; - d++; - } - return 0; -}
--- a/src/testdebug.c Mon May 18 15:55:05 2009 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -#include "define.h" - -#define BUF_SIZE 100000 - -int main(int argc, const char** argv) { - char *x = pst_malloc(BUF_SIZE); // 10k - memset(x, '.', BUF_SIZE-1); - x[BUF_SIZE-2]='P'; - x[BUF_SIZE-1]='\0'; - - DEBUG_INIT("libpst.log"); - DEBUG_REGISTER_CLOSE(); - - DEBUG_ENT("main"); - - DEBUG_FILE(("%s", x)); - DEBUG_FILE(("This is an error %d\n", 4)); - - DEBUG_RET(); - return 0; -} -