Fixes the `-t bytes -x` combinantion in `search` command and adds more tests to it (#2476)

* Avoid encoding to UTF-8 in `search` when `hex` is given

* Add tests for the more elemental `search` options
pull/2477/head
Matt. 1 year ago committed by GitHub
parent c80a773be5
commit f945b417da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -267,7 +267,7 @@ def search(
# [1]: https://sourceware.org/git/?p=binutils-gdb.git;a=blame;f=gdb/python/py-inferior.c;h=a1042ee72ac733091f7572bc04b072546d3c1519;hb=23c84db5b3cb4e8a0d555c76e1a0ab56dc8355f3
# [2]: https://docs.python.org/3.1/c-api/arg.html#strings-and-buffers
elif type == "bytes":
elif type == "bytes" and not hex:
try:
value = value.encode("utf-8")
except UnicodeError as what:

@ -10,6 +10,8 @@ void break_here(void) {}
size_t marker = 0xABCDEF1234567890;
static const char* literal = "Hello!";
int main(void)
{
void *p;

@ -1,5 +1,7 @@
from __future__ import annotations
import re
import gdb
import tests
@ -9,6 +11,27 @@ SEARCH_PATTERN = 0xD00DBEEF
SEARCH_PATTERN2 = 0xABCDEF1234567890
def test_command_search_literal(start_binary):
"""
Searches for a string literal in a few different ways
"""
start_binary(SEARCH_BINARY)
gdb.execute("break break_here")
gdb.execute("run")
# Perform three equivalent searches, and chop off the first line of verbosity.
result0 = gdb.execute("search -t bytes Hello!", to_string=True).splitlines()[1:]
result1 = gdb.execute("search -t bytes -x 48656c6c6f21", to_string=True).splitlines()[1:]
result2 = gdb.execute("search -t string Hello!", to_string=True).splitlines()[1:]
assert result0 == result1
assert result1 == result2
for line in result0:
assert re.match(".* .* 0x216f6c6c6548 /\\* 'Hello!' \\*/", line) is not None
def test_command_search_limit_single_page(start_binary):
"""
Tests simple search limit for single memory page

Loading…
Cancel
Save