From: Ulrich Drepper Date: Wed, 31 Dec 2008 20:03:45 +0000 (-0800) Subject: Replay output operations correctly when internal buffer in x86/x86-64 X-Git-Tag: elfutils-0.138~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a492e8ec781c08bd233b2564e5c0f1a8cf0378cb;p=thirdparty%2Felfutils.git Replay output operations correctly when internal buffer in x86/x86-64 disasembler code is full. --- diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index b3abff7bf..5bc89f9fd 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -1,5 +1,7 @@ 2008-12-31 Ulrich Drepper + * i386_disasm.c (i386_disasm): Correct resizing of buffer. + * i386_parse.y (struct argstring): Add off element. (off_op_str): New global variable. (print_op_str): Print strings as concatenated strings. Keep track diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c index 3ba513b40..76b5a3937 100644 --- a/libcpu/i386_disasm.c +++ b/libcpu/i386_disasm.c @@ -356,6 +356,9 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, prefixes |= ((*data++) & 0xf) | has_rex; #endif + bufcnt = 0; + size_t cnt = 0; + const uint8_t *curr = match_data; const uint8_t *const match_end = match_data + sizeof (match_data); @@ -369,30 +372,6 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, goto do_ret; } - if (0) - { - /* Resize the buffer. */ - char *oldbuf; - enomem: - oldbuf = buf; - if (buf == initbuf) - buf = malloc (2 * bufsize); - else - buf = realloc (buf, 2 * bufsize); - if (buf == NULL) - { - buf = oldbuf; - retval = ENOMEM; - goto do_ret; - } - bufsize *= 2; - - output_data.bufp = buf; - output_data.bufsize = bufsize; - } - bufcnt = 0; - - size_t cnt = 0; next_match: while (curr < match_end) { @@ -447,6 +426,41 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, || (prefixes & correct_prefix) != 0); prefixes ^= correct_prefix; + if (0) + { + /* Resize the buffer. */ + char *oldbuf; + enomem: + oldbuf = buf; + if (buf == initbuf) + buf = malloc (2 * bufsize); + else + buf = realloc (buf, 2 * bufsize); + if (buf == NULL) + { + buf = oldbuf; + retval = ENOMEM; + goto do_ret; + } + bufsize *= 2; + + output_data.bufp = buf; + output_data.bufsize = bufsize; + bufcnt = 0; + + if (data == end) + { + assert (prefixes != 0); + goto print_prefix; + } + + /* gcc is not clever enough to see the following variables + are not used uninitialized. */ + asm ("" + : "=mr" (opoff), "=mr" (correct_prefix), "=mr" (codep), + "=mr" (start), "=mr" (len)); + } + size_t prefix_size = 0; // XXXonly print as prefix if valid?