Skip to content

Fix crash when architecture string has no hyphen after colon#1001

Merged
xusheng6 merged 1 commit intodevfrom
fix/issue-1000-architecture-replace-crash
Feb 26, 2026
Merged

Fix crash when architecture string has no hyphen after colon#1001
xusheng6 merged 1 commit intodevfrom
fix/issue-1000-architecture-replace-crash

Conversation

@xusheng6
Copy link
Copy Markdown
Member

Summary

  • Fixes crash in GDB RSP adapter when connecting to QEMU-PPC targets
  • Architecture strings like powerpc:common contain a colon but no hyphen
  • string::find('-') was returning npos, which when passed to replace() causes a crash
  • Added npos check before calling replace() in all 3 affected adapters: gdbadapter.cpp, corelliumadapter.cpp, and esrevenadapter.cpp

Fixes #1000

Test plan

  • Connect to QEMU-PPC target with architecture string powerpc:common
  • Verify debugger no longer crashes on connection
  • Test with architecture strings that DO contain hyphens to ensure backward compatibility

🤖 Generated with Claude Code

When connecting to QEMU-PPC targets, the architecture string may be
"powerpc:common" which contains a colon but no hyphen. The code was
calling string::replace() with the result of string::find('-') without
checking if find() returned npos, causing a crash.

This fix adds a check for npos before calling replace() in all three
affected adapter files.

Fixes #1000

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@xusheng6 xusheng6 merged commit 9c3d024 into dev Feb 26, 2026
1 check passed
@xusheng6 xusheng6 deleted the fix/issue-1000-architecture-replace-crash branch February 26, 2026 07:47
xusheng6 added a commit that referenced this pull request Feb 26, 2026
When connecting to big-endian targets like PowerPC via QEMU, register
values were being incorrectly parsed using little-endian byte order.
This caused wrong PC values and prevented proper memory reads.

Changes:
- Parse <endian> element from target description XML when available
- Add IsBigEndianArchitecture() fallback for known BE architectures
  (PowerPC, SPARC, M68K, S/390)
- Add m_isBigEndian member variable to track target endianness
- Add parseBigEndianHexToUint512() for reading BE register values
- Add uint512ToBigEndianHex() for writing BE register values
- Update ReadAllRegisters() and WriteRegister() to use correct
  endianness based on target

Fixes #1000 (partial - the crash fix was in PR #1001, this addresses
the endianness issue that remained after the crash was fixed)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
xusheng6 added a commit that referenced this pull request Feb 27, 2026
* Fix big-endian register parsing for PowerPC and other BE targets

When connecting to big-endian targets like PowerPC via QEMU, register
values were being incorrectly parsed using little-endian byte order.
This caused wrong PC values and prevented proper memory reads.

Changes:
- Parse <endian> element from target description XML when available
- Add IsBigEndianArchitecture() fallback for known BE architectures
  (PowerPC, SPARC, M68K, S/390)
- Add m_isBigEndian member variable to track target endianness
- Add parseBigEndianHexToUint512() for reading BE register values
- Add uint512ToBigEndianHex() for writing BE register values
- Update ReadAllRegisters() and WriteRegister() to use correct
  endianness based on target

Fixes #1000 (partial - the crash fix was in PR #1001, this addresses
the endianness issue that remained after the crash was fixed)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix parseBigEndianHexToUint512 buffer placement and add forward declarations

Right-justify bytes in the 64-byte buffer before calling intx::be::load,
which expects MSB at buffer[0] for a full 512-bit value. Without this,
a 4-byte register like PC=0x4082e4c0 was placed at buffer[0..3] and
interpreted as the top 32 bits of a 512-bit number.

Also add forward declarations for IsBigEndianArchitecture to fix
compilation errors (function defined after first use in LoadRegisterInfo).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when connecting to qemu-ppc with GDB RSP adapter

1 participant