[PATCH v3 2/7] amd64_analyze_prologue: swap upper bound check condition operands

Victor Collod
2020-06-24T01:29:09Z

`if (current_pc <= pc)' felt backwards, as current_pc doesn't change,
and the test could be described as "stop if pc went past current_pc".

2020-06-23 Victor Collod <vcollod@nvidia.com>

* amd64-tdep.c (amd64_analyze_prologue): Swap upper bound check
condition operands.
---
gdb/amd64-tdep.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 0ce9fbc2997..ff12cb874b8 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2387,7 +2387,8 @@ amd64_analyze_prologue (struct gdbarch *gdbarch,
gdb_byte buf[3];
gdb_byte op;

- if (current_pc <= pc)
+ /* Analysis must not go past current_pc. */
+ if (pc >= current_pc)
return current_pc;

if (gdbarch_ptr_bit (gdbarch) == 32)
@@ -2408,7 +2409,8 @@ amd64_analyze_prologue (struct gdbarch *gdbarch,
op = read_code_unsigned_integer (pc, 1, byte_order);
}

- if (current_pc <= pc)
+ /* If we went past the allowed bound, stop. */
+ if (pc >= current_pc)
return current_pc;

if (op == 0x55) /* pushq %rbp */
@@ -2418,8 +2420,8 @@ amd64_analyze_prologue (struct gdbarch *gdbarch,
cache->saved_regs[AMD64_RBP_REGNUM] = 0;
cache->sp_offset += 8;

- /* If that's all, return now. */
- if (current_pc <= pc + 1)
+ /* If we went past the allowed bound, stop. */
+ if (pc + 1 >= current_pc)
return current_pc;

read_code (pc + 1, buf, 3);
--
2.20.1