]> code.delx.au - gnu-emacs-elpa/blob - packages/realgud/test/test-regexp-gdb.el
1975982cddd8893d843f54dcf4c8c6178ab0b85f
[gnu-emacs-elpa] / packages / realgud / test / test-regexp-gdb.el
1 (require 'test-simple)
2 (require 'load-relative)
3 (load-file "../realgud/common/buffer/command.el")
4 (load-file "../realgud/debugger/gdb/init.el")
5 (load-file "./regexp-helper.el")
6
7 (declare-function __FILE__ 'load-relative)
8
9 (test-simple-start)
10
11 (eval-when-compile
12 (defvar dbg-name) (defvar realgud-pat-hash) (defvar realgud-bt-hash)
13 (defvar loc-pat) (defvar prompt-pat) (defvar s1)
14 (defvar file-group) (defvar line-group) (defvar pos)
15 (defvar test-dbgr) (defvar test-text)
16 )
17
18 ; Some setup usually done in setting up the buffer.
19 ; We customize this for this debugger.
20 ; FIXME: encapsulate this.
21 (setq dbg-name "gdb")
22
23 (setq loc-pat (gethash "loc" (gethash dbg-name realgud-pat-hash)))
24 (setq test-dbgr (make-realgud-cmdbuf-info
25 :debugger-name dbg-name
26 :loc-regexp (realgud-loc-pat-regexp loc-pat)
27 :file-group (realgud-loc-pat-file-group loc-pat)
28 :line-group (realgud-loc-pat-line-group loc-pat)))
29
30 ;; FIXME: we get a void variable somewhere in here when running
31 ;; even though we define it in lexical-let. Dunno why.
32 ;; setq however will workaround this.
33 (setq test-text "\1a\1a/home/rocky/c/ctest.c:80:2000:beg:0x8048748>")
34 (note "traceback location matching")
35
36 (assert-t (numberp (cmdbuf-loc-match test-text test-dbgr)) "basic location")
37 (assert-equal "/home/rocky/c/ctest.c"
38 (match-string (realgud-cmdbuf-info-file-group test-dbgr)
39 test-text) "extract file name")
40 (assert-equal "80"
41 (match-string (realgud-cmdbuf-info-line-group test-dbgr)
42 test-text) "extract line number")
43 (note "debugger-backtrace")
44 (setq realgud-bt-pat (gethash "debugger-backtrace"
45 realgud:gdb-pat-hash))
46 (setq s1
47 "#0 main (argc=2, argv=0xbffff564, envp=0xbffff570) at main.c:935
48 #1 0xb7e9f4a5 in *__GI___strdup (s=0xbffff760 \"/tmp/remake/remake\") at strdup.c:42
49 #2 0x080593ac in main (argc=2, argv=0xbffff5a4, envp=0xbffff5b0)
50 at main.c:952
51 #46 0xb7f51b87 in vm_call_cfunc (th=0x804d188, reg_cfp=0xb7ba9e88, num=0,
52 recv=157798080, blockptr=0x0, me=0x80d12a0) at vm_insnhelper.c:410
53 ")
54 (setq realgud-bt-re (realgud-loc-pat-regexp realgud-bt-pat))
55 (setq file-group (realgud-loc-pat-file-group realgud-bt-pat))
56 (setq line-group (realgud-loc-pat-line-group realgud-bt-pat))
57 (assert-equal 0 (string-match realgud-bt-re s1))
58 (assert-equal "main.c"
59 (substring s1
60 (match-beginning file-group)
61 (match-end file-group)))
62 (assert-equal "935"
63 (substring s1
64 (match-beginning line-group)
65 (match-end line-group)))
66
67 (setq pos (match-end 0))
68 (assert-equal 65 pos)
69 (assert-equal 65 (string-match realgud-bt-re s1 pos))
70 (assert-equal "strdup.c"
71 (substring s1
72 (match-beginning file-group)
73 (match-end file-group)))
74 (assert-equal "42"
75 (substring s1
76 (match-beginning line-group)
77 (match-end line-group)))
78
79 (setq pos (match-end 0))
80 (assert-equal 149 pos)
81 (assert-equal 149 (string-match realgud-bt-re s1 pos))
82 (assert-equal "main.c"
83 (substring s1
84 (match-beginning file-group)
85 (match-end file-group)))
86 (assert-equal "952"
87 (substring s1
88 (match-beginning line-group)
89 (match-end line-group)))
90
91 (setq pos (match-end 0))
92 (assert-equal 233 pos)
93 (assert-equal 233 (string-match realgud-bt-re s1 pos))
94 (assert-equal "vm_insnhelper.c"
95 (substring s1
96 (match-beginning file-group)
97 (match-end file-group)))
98 (assert-equal "410"
99 (substring s1
100 (match-beginning line-group)
101 (match-end line-group)))
102
103 (note "prompt")
104 (set (make-local-variable 'prompt-pat)
105 (gethash "prompt" realgud:gdb-pat-hash))
106 (prompt-match "(gdb) ")
107
108 (end-tests)