Keresés

Részletes keresés

NevemTeve Creative Commons License 2023.09.19 0 0 64

@ módosító tömbelemek kiírására:

 

(gdb) print *argv@4
$4 = {0x7fffffffe16f "/home/teve/proba/echo", 0x7fffffffe18e "elso", 0x7fffffffe193 "masodik", 0x7fffffffe19b "har madik"}

NevemTeve Creative Commons License 2023.06.18 0 0 63

print milyen hosszan írja ki a stringeket:

set print elements n

default=200, 0=unlimited

NevemTeve Creative Commons License 2023.04.18 0 0 62

Nagyon hasznos: színes kiírás letiltása:
set style enabled off

NevemTeve Creative Commons License 2023.01.06 0 0 61

Ezt most olvastam az interneten:
$ gdb -p 23117 -batch -ex 'print (int)close(4)'

NevemTeve Creative Commons License 2022.12.09 0 0 60

További hasznos információk:

info proc

info proc mappings

info proc stat

info proc status

Előzmény: NevemTeve (13)
NevemTeve Creative Commons License 2020.04.15 0 0 59

Aztán itt van a catch syscall: álljon meg bármilyen rendszerhívásnál. Tovább opciók:

 

(gdb) help catch
Set catchpoints to catch events.

List of catch subcommands:

catch assert -- Catch failed Ada assertions
catch catch -- Catch an exception
catch exception -- Catch Ada exceptions
catch exec -- Catch calls to exec
catch fork -- Catch calls to fork
catch handlers -- Catch Ada exceptions
catch load -- Catch loads of shared libraries
catch rethrow -- Catch an exception
catch signal -- Catch signals by their names and/or numbers
catch syscall -- Catch system calls by their names
catch throw -- Catch an exception
catch unload -- Catch unloads of shared libraries
catch vfork -- Catch calls to vfork

NevemTeve Creative Commons License 2020.01.30 0 0 58

Sőt, lehet többet is:

 

set exec-wrapper env 'LD_PRELOAD=/usr/lib/libefence.so' 'LD_DEBUG=1'

Előzmény: NevemTeve (57)
NevemTeve Creative Commons License 2019.12.01 0 0 57

A leggyakoribb használati esetem:

 

set exec-wrapper env 'LD_PRELOAD=/usr/lib/libefence.so'

Előzmény: NevemTeve (42)
NevemTeve Creative Commons License 2019.04.24 0 0 56

+1 példa breakpoint-ra:

break *(&lxu4CnvCase+24)

NevemTeve Creative Commons License 2018.08.14 0 0 55

Feltételes breakpoint:

b xcoffread.c:1128 if cs->c_symnum==688

commands

 printf "name="%s" symnum=%d naux=%d sclass=%d secnum=%d type=%d\n", cs->c_name, cs->c_symnum, cs->c_naux, cs->c_sclass, cs->c_secnum, cs->c_type

end

 

Előzmény: NevemTeve (54)
NevemTeve Creative Commons License 2018.07.28 0 0 54

példa olyan breakpoint-ra, amikor előre megadjuk, mi történjen:

break __loadx
commands
silent
printf "__loadx \"%s\"\n",$r6
cont
end

Előzmény: NevemTeve (-)
NevemTeve Creative Commons License 2018.07.23 0 0 53

A run egy változata a start: ideiglenes breakpoint-ot tesz a 'main'-re, és elindítja a programot

 

4.2 Starting your program

Előzmény: NevemTeve (2)
NevemTeve Creative Commons License 2018.01.21 0 0 52

AIX-on az első 6 paraméter az r3-r8 regiszterben jön, a többit így lehet megnézni (64-biten):

(gdb) x/4xg *(long **)$r1+14
0xfffffffffffcee0:      0x000000000000000c      0x0000000110660db0 ; par7 par8
0xfffffffffffcef0:      0x0000000000000000      0x0000000000000008 ; par9 par10

NevemTeve Creative Commons License 2017.11.22 0 0 51

További info-k összes változó, lokális változók, paraméterek:

 

info variables

info locals

info args

NevemTeve Creative Commons License 2017.05.08 0 0 50

Konkrét címre is lehet breakpointot tenni: b *0x0000000100089678

NevemTeve Creative Commons License 2017.03.18 0 0 49
NevemTeve Creative Commons License 2017.03.11 0 0 48

Most találtam, hogyan lehet a tesztelendő programnak paramétereket átadni a parancssorból:

gdb ... --args executable arg1 arg2 ...

NevemTeve Creative Commons License 2016.08.19 0 0 47

Szintén gépikód szintű információ az 'info line'

 

(gdb) info line
Line 7 of "hello.c" starts at address 0x80483ed <main+9> and ends at 0x80483f9 <main+21>.

Előzmény: NevemTeve (46)
NevemTeve Creative Commons License 2016.08.19 0 0 46

A disass /m main pedig belevegyíti a forrásprogramot is:

 

(gdb) disass /m main
Dump of assembler code for function main:
6    {
   0x080483e4 <+0>:    push   %ebp
   0x080483e5 <+1>:    mov    %esp,%ebp
   0x080483e7 <+3>:    and    $0xfffffff0,%esp
   0x080483ea <+6>:    sub    $0x10,%esp

7        puts ("hello");
   0x080483ed <+9>:    movl   $0x80484c0,(%esp)
   0x080483f4 <+16>:    call   0x8048300 <puts@plt>

8        return 0;
   0x080483f9 <+21>:    mov    $0x0,%eax

9    }
   0x080483fe <+26>:    leave  
   0x080483ff <+27>:    ret    

End of assembler dump.

Előzmény: NevemTeve (22)
NevemTeve Creative Commons License 2016.08.19 0 0 45

Mit tegyünk, ha a 'main'-ig el sem jut a program?

Megpróbálhatunk megállási pontot tenni pl a '_start' szimbumra, bár ez platformfüggő lehet.

NevemTeve Creative Commons License 2016.05.05 0 0 44

Namostan lehet, hogy a hívott nem állítja az EBP-t, akkor:

 

(gdb) x/4x $esp+8 # paraméterek

(gdb) print ((char **)$esp)[1] # 1. param (ha string)

(gdb) print ((int32_t *)$esp)[2] # 2. param (ha integer)

Előzmény: NevemTeve (31)
NevemTeve Creative Commons License 2016.04.21 0 0 43

Hol a csodában járunk is most?

 

(gdb) p/x $pc
$6 = 0x7ffff4f36271


(gdb) x $pc
0x7ffff4f36271 <lp_state_directory+4>:    0xd8058d48


(gdb) info symbol $pc
lp_state_directory + 4 in section .text of /local/usr/local/src/samba-4.4.2/bin/shared/libsmbconf.so.0

NevemTeve Creative Commons License 2016.03.03 0 0 42

Speciel most csak így működött (másik gép, másik OS, másik verzió?):

 

    $ gdb program

    (gdb) set exec-wrapper env 'LD_PRELOAD=/home/projects/lib64/libmemtrace.so'

    (gdb) run

Előzmény: NevemTeve (29)
NevemTeve Creative Commons License 2016.01.05 0 0 41

Valamint itt van a finish: addig fusson, míg az aktuális függvényből ki nem lépünk.

Előzmény: NevemTeve (-)
NevemTeve Creative Commons License 2015.08.18 0 0 40
NevemTeve Creative Commons License 2015.08.13 0 0 39
NevemTeve Creative Commons License 2015.08.11 0 0 38

Ha hosszú a parancs kimenete:

 

(gdb) set logging on

Copying output to gdb.txt.
(gdb) info sh # vagy amit gondolunk

(gdb) set logging off

 

NevemTeve Creative Commons License 2014.08.18 0 0 37
NevemTeve Creative Commons License 2013.11.15 0 0 36

Na, bevallom, nem tudtam, mi az az 'r9d'. Hát az nem más, mint az r9 alsó 32 bitje. Lásd itt:

http://msdn.microsoft.com/en-us/library/windows/hardware/ff561499%28v=vs.85%29.aspx

NevemTeve Creative Commons License 2013.11.15 0 0 35

Ha esetleg még az intel rabigájában nyögünk:

 

(gdb) set disassembly-flavor intel

Ha kedveled azért, ha nem azért nyomj egy lájkot a Fórumért!