diff options
author | Ulrich Drepper <drepper@redhat.com> | 2008-01-11 10:12:18 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2008-01-11 10:12:18 +0000 |
commit | 5eee122f63233ad4df924fedceab5e2649922aeb (patch) | |
tree | dc1fb9534fedc5f669eb4c3caa75f5ebeca8675e /libcpu | |
parent | 8a3ca3a85e6fe3f5118142517606f5c89799a903 (diff) | |
download | elfutils-5eee122f63233ad4df924fedceab5e2649922aeb.tar.gz |
Cleanups in libasm abd objdump.
Diffstat (limited to 'libcpu')
-rw-r--r-- | libcpu/ChangeLog | 2 | ||||
-rw-r--r-- | libcpu/i386_data.h | 2 | ||||
-rw-r--r-- | libcpu/i386_disasm.c | 40 |
3 files changed, 20 insertions, 24 deletions
diff --git a/libcpu/ChangeLog b/libcpu/ChangeLog index cbfcd755..cb0f4edf 100644 --- a/libcpu/ChangeLog +++ b/libcpu/ChangeLog @@ -2,6 +2,8 @@ * i386_disasm.c (i386_disasm): Resize output buffer if necessary. Optimize output_data initialization. Free buffers before return. + (struct output_data): Remove op1str field. Adjust code. + (i386_disasm): Store final NUL btye at end of functions. 2008-01-10 Ulrich Drepper <drepper@redhat.com> diff --git a/libcpu/i386_data.h b/libcpu/i386_data.h index 5f66c610..89fa3089 100644 --- a/libcpu/i386_data.h +++ b/libcpu/i386_data.h @@ -1,4 +1,4 @@ -/* Helper routines for disassembler for x86-64. +/* Helper routines for disassembler for x86/x86-64. Copyright (C) 2007, 2008 Red Hat, Inc. This file is part of Red Hat elfutils. Written by Ulrich Drepper <drepper@redhat.com>, 2007. diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c index dd7bfca4..2a843923 100644 --- a/libcpu/i386_disasm.c +++ b/libcpu/i386_disasm.c @@ -188,7 +188,6 @@ struct output_data { GElf_Addr addr; int *prefixes; - const char *op1str; size_t opoff1; size_t opoff2; size_t opoff3; @@ -467,9 +466,6 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, data = begin + 1; ++addr; - /* The string definitely fits. */ - buf[bufcnt++] = '\0'; - goto out; } @@ -659,6 +655,7 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, { case suffix_none: break; + case suffix_w: if ((codep[-1] & 0xc0) != 0xc0) { @@ -681,14 +678,17 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, ADD_CHAR (ch); } break; + case suffix_w0: if ((codep[-1] & 0xc0) != 0xc0) ADD_CHAR ('l'); break; + case suffix_w1: if ((data[0] & 0x4) == 0) ADD_CHAR ('l'); break; + case suffix_W: if (prefixes & has_data16) { @@ -700,6 +700,7 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, ADD_CHAR ('q'); #endif break; + case suffix_W1: if (prefixes & has_data16) { @@ -720,10 +721,12 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, }; ADD_STRING (tttn[codep[-1 - instrtab[cnt].modrm] & 0x0f]); break; + case suffix_D: if ((codep[-1] & 0xc0) != 0xc0) ADD_CHAR ((data[0] & 0x04) == 0 ? 's' : 'l'); break; + default: printf("unknown suffix %d\n", instrtab[cnt].suffix); abort (); @@ -739,7 +742,6 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, if (instrtab[cnt].str1 != 0) ADD_STRING (op1_str[instrtab[cnt].str1]); - output_data.op1str = op1_str[instrtab[cnt].str1]; output_data.opoff1 = (instrtab[cnt].off1_1 + OFF1_1_BIAS - opoff); output_data.opoff2 = (instrtab[cnt].off1_2 @@ -752,7 +754,7 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, if (r > 0) goto enomem; - string_end_idx = ~0ul; + string_end_idx = bufcnt; } else if (prec == 2 && instrtab[cnt].fct2 != 0) { @@ -760,7 +762,6 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, if (instrtab[cnt].str2 != 0) ADD_STRING (op2_str[instrtab[cnt].str2]); - output_data.op1str = op2_str[instrtab[cnt].str2]; output_data.opoff1 = (instrtab[cnt].off2_1 + OFF2_1_BIAS - opoff); output_data.opoff2 = (instrtab[cnt].off2_2 @@ -773,7 +774,7 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, if (r > 0) goto enomem; - string_end_idx = ~0ul; + string_end_idx = bufcnt; } else if (prec == 3 && instrtab[cnt].fct3 != 0) { @@ -781,7 +782,6 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, if (instrtab[cnt].str3 != 0) ADD_STRING (op3_str[instrtab[cnt].str3]); - output_data.op1str = op3_str[instrtab[cnt].str3]; output_data.opoff1 = (instrtab[cnt].off3_1 + OFF3_1_BIAS - opoff); output_data.opoff2 = (instrtab[cnt].off3_2 @@ -798,17 +798,9 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, if (r > 0) goto enomem; - string_end_idx = ~0ul; + string_end_idx = bufcnt; } break; - - case 'e': - /* String end marker. */ - if (string_end_idx == ~0ul) - string_end_idx = bufcnt; - /* No padding. */ - width = 0; - break; } /* Pad according to the specified width. */ @@ -820,8 +812,8 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, if ((prefixes & SEGMENT_PREFIXES) != 0) goto print_prefix; - if (string_end_idx != ~0ul) - buf[string_end_idx] = '\0'; + assert (string_end_idx != ~0ul); + bufcnt = string_end_idx; addr += param_start - begin; data = param_start; @@ -837,11 +829,13 @@ i386_disasm (const uint8_t **startp, const uint8_t *end, GElf_Addr addr, ADD_STRING ("(bad)"); addr += data - begin; - buf[bufcnt++] = '\0'; - out: + if (bufcnt == bufsize) + goto enomem; + buf[bufcnt] = '\0'; + *startp = data; - retval = outcb (buf, strlen (buf), outcbarg); + retval = outcb (buf, bufcnt, outcbarg); if (retval != 0) goto do_ret; } |