mirror of https://github.com/pwndbg/pwndbg.git
* Added -r argument to telescope command (#1047) * Added tests for telescope command (#1047)pull/1100/head
parent
890e314f2f
commit
5d358585b1
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct A {
|
||||
void* func_ptr;
|
||||
void* stack_ptr;
|
||||
void* heap_ptr;
|
||||
char buf[16];
|
||||
char gap[128];
|
||||
};
|
||||
|
||||
void break_here() {}
|
||||
|
||||
int main() {
|
||||
struct A a = {};
|
||||
a.func_ptr = (void*)main;
|
||||
a.stack_ptr = (void*) &a;
|
||||
a.heap_ptr = malloc(10);
|
||||
strcpy(a.buf, "aaa");
|
||||
break_here();
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
import gdb
|
||||
|
||||
import tests
|
||||
|
||||
TELESCOPE_BINARY = tests.binaries.get('telescope_binary.out')
|
||||
|
||||
|
||||
def test_command_telescope(start_binary):
|
||||
"""
|
||||
Tests simple telescope
|
||||
"""
|
||||
start_binary(TELESCOPE_BINARY)
|
||||
|
||||
gdb.execute('break break_here')
|
||||
gdb.execute('run')
|
||||
gdb.execute('up')
|
||||
|
||||
expected_str = gdb.execute('print a', to_string=True)
|
||||
expected_lines = expected_str.split('\n')
|
||||
|
||||
result_str = gdb.execute('telescope &a', to_string=True)
|
||||
result_lines = result_str.split('\n')
|
||||
|
||||
for i in range(4):
|
||||
expected_addr = expected_lines[i+1].split(' ')[4].strip(',"')
|
||||
assert expected_addr in result_lines[i]
|
||||
|
||||
|
||||
def test_command_telescope_reverse(start_binary):
|
||||
"""
|
||||
Tests reversed telescope
|
||||
"""
|
||||
start_binary(TELESCOPE_BINARY)
|
||||
|
||||
gdb.execute('break break_here')
|
||||
gdb.execute('run')
|
||||
gdb.execute('up')
|
||||
|
||||
expected_str = gdb.execute('print a', to_string=True)
|
||||
expected_lines = expected_str.split('\n')
|
||||
|
||||
result_str = gdb.execute('telescope ((uint8_t*)&a)+0x38 -r', to_string=True)
|
||||
result_lines = result_str.split('\n')
|
||||
|
||||
for i in range(4):
|
||||
expected_addr = expected_lines[i+1].split(' ')[4].strip(',"')
|
||||
assert expected_addr in result_lines[i]
|
||||
|
||||
|
||||
def test_command_telescope_n_records(start_binary):
|
||||
"""
|
||||
Tests telescope defined number of records
|
||||
"""
|
||||
start_binary(TELESCOPE_BINARY)
|
||||
|
||||
n = 3
|
||||
gdb.execute('entry')
|
||||
result_str = gdb.execute('telescope $rsp {}'.format(n), to_string=True)
|
||||
assert len(result_str.strip('\n').split('\n')) == n
|
||||
Loading…
Reference in new issue