Fix deference-limit changes not being reflected due to an early cast to int() (#2422)

* Added types to hexdump()'s parameters

* hexdump(): upgraded format strings to f-strings, while fixing the offset when data is empty

* hexdump(): offset is now correctly computed and updated accross repeated calls to hexdump.

This fixes two bugs:
1. Offset was increased by the number of lines displayed by the hexdump() command,
	which was incorrect, as some lines may be compressed;
2. When dumping a number of bytes that is not divisible by the number of bytes per line,
	offset would be incorrectly updated.

* Linter

* hexdump: fixed type of retrieved config entry hexdump_group_use_big_endian

* Fixed test_hexdump_saved_address_and_offset test to account for random stack address

* Upgraded the linked-lists.c test program to 6 items in order to test the "deference-limit" setting

* Chain: changes to the deference-limit parameter were not reflected in the program due to an early cast to int()

* Linter
pull/2423/head
Charles Fol 1 year ago committed by GitHub
parent 94f82fff79
commit d65d5814c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -30,7 +30,7 @@ c = ColorConfig(
def get(
address: int | None,
limit: int = int(LIMIT),
limit: int = LIMIT,
offset: int = 0,
hard_stop: int | None = None,
hard_end: int = 0,
@ -98,7 +98,7 @@ config_contiguous = theme.add_param(
def format(
value: int | List[int] | None,
limit: int = int(LIMIT),
limit: int = LIMIT,
code: bool = True,
offset: int = 0,
hard_stop: int | None = None,

@ -6,7 +6,10 @@ struct node {
int value;
struct node *next;
};
struct node node_c = { 2, NULL };
struct node node_f = { 5, NULL };
struct node node_e = { 4, &node_f };
struct node node_d = { 3, &node_e };
struct node node_c = { 2, &node_d };
struct node node_b = { 1, &node_c };
struct node node_a = { 0, &node_b };

@ -9,7 +9,7 @@ import tests
LINKED_LISTS_BINARY = tests.binaries.get("linked-lists.out")
def startup(start_binary):
def startup(start_binary) -> None:
start_binary(LINKED_LISTS_BINARY)
gdb.execute("break break_here")
@ -17,6 +17,66 @@ def startup(start_binary):
gdb.execute("up")
def test_command_plist_dereference_limit_change_has_impact_on_plist(start_binary):
"""
Tests the plist command with different dereference limits
"""
startup(start_binary)
gdb.execute("set dereference-limit 5")
expected_out = re.compile(
"""\
0[xX][0-9a-fA-F]+ <node_a>: {\\s*
value = 0,\\s*
next = 0[xX][0-9a-fA-F]+ <node_b>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_b>: {\\s*
value = 1,\\s*
next = 0[xX][0-9a-fA-F]+ <node_c>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_c>: {\\s*
value = 2,\\s*
next = 0[xX][0-9a-fA-F]+ <node_d>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_d>: {\\s*
value = 3,\\s*
next = 0[xX][0-9a-fA-F]+ <node_e>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_e>: {\\s*
value = 4,\\s*
next = 0[xX][0-9a-fA-F]+ <node_f>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_f>: {\\s*
value = 5,\\s*
next = 0x0\\s*
}\
"""
)
result_str = gdb.execute("plist node_a next", to_string=True)
assert expected_out.match(result_str) is not None
gdb.execute("set dereference-limit 1")
expected_out = re.compile(
"""\
0[xX][0-9a-fA-F]+ <node_a>: {\\s*
value = 0,\\s*
next = 0[xX][0-9a-fA-F]+ <node_b>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_b>: {\\s*
value = 1,\\s*
next = 0[xX][0-9a-fA-F]+ <node_c>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_c>: {\\s*
value = 2,\\s*
next = 0[xX][0-9a-fA-F]+ <node_d>\\s*
}\
"""
)
result_str = gdb.execute("plist node_a next", to_string=True)
assert expected_out.match(result_str) is not None
def test_command_plist_flat_no_flags(start_binary):
"""
Tests the plist for a non-nested linked list
@ -35,8 +95,21 @@ def test_command_plist_flat_no_flags(start_binary):
}\\s*
0[xX][0-9a-fA-F]+ <node_c>: {\\s*
value = 2,\\s*
next = 0[xX][0-9a-fA-F]+ <node_d>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_d>: {\\s*
value = 3,\\s*
next = 0[xX][0-9a-fA-F]+ <node_e>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_e>: {\\s*
value = 4,\\s*
next = 0[xX][0-9a-fA-F]+ <node_f>\\s*
}\\s*
0[xX][0-9a-fA-F]+ <node_f>: {\\s*
value = 5,\\s*
next = 0x0\\s*
}"""
}\
"""
)
result_str = gdb.execute("plist node_a next", to_string=True)

Loading…
Cancel
Save