On 2022-08-01, Eli Zaretskii (
el...@gnu.org) [via
dj...@delorie.com]
<
dj...@delorie.com> wrote:
> Why is it important to profile such toy programs? What real-life
> problem did you encounter that led you to try the above?
Thank you for your response. The "real-life problem" happened when i
tried to profile a game named Angband 4.2.4. I compiled and linked
angband with -pg and when i ran angband.exe i got the error below [1].
I am also including a short gdb trace below [2] and the definition of
the argv0 variable below [3].
This crash only happens when i build angband with -pg. It does not
happen in a normal build nor in a debug build.
I wrote the toy program in an attempt to simplify the situation and get
more familiar with gprof.
-Ben
[1]
Exiting due to signal SIGSEGV
Page fault at eip=00150b91, error=0004
eax=00181afc ebx=00000000 ecx=00000000 edx=002e7b84 esi=0022e198
edi=0000000c
ebp=0022db88 esp=0022db60 program=C:\GAMES\ANGBAND\ANGBAND.EXE
cs: sel=00a7 base=00400000 limit=002effff
ds: sel=00af base=00400000 limit=002effff
es: sel=00af base=00400000 limit=002effff
fs: sel=008f base=00005920 limit=0000ffff
gs: sel=00bf base=00000000 limit=0010ffff
ss: sel=00af base=00400000 limit=002effff
App stack: [0022dbf8..001adbfc] Exceptn stack: [001adb48..001abc08]
Call frame traceback EIPs:
0x00150b91
[2]
(gdb) l main
313 * Note the special "--" option which terminates the processing
of
314 * standard options. All non-standard options (if any) are
passed
315 * directly to the "init_xxx()" function.
316 */
317 int main(int argc, char *argv[])
318 {
319 int i;
320 bool new_game = alse, select_game = false;
321 bool done = false;
322
(gdb) l
323 const char *mstr = NULL;
324 bool args = true;
325
326 /* Save the "program name" XXX XXX XXX */
327 argv0 = argv[0];
328
...
(gdb) b 327
Breakpoint 1 at 0x150b91: file main.c, line 327.
(gdb) r
Starting program: c:/games/angband/angband.exe
Breakpoint 1, main (argc=1, argv=0x22e3b0) at main.c:327
327 argv0 = argv[0];
(gdb) p argv
$1 = (char **) 0x22e3b0
(gdb) p argv[0]
$2 = 0x22e350 "c:/games/angband/angband.exe"
(gdb) p argv0
$3 = 0x0
(gdb) p &argv0
$4 = (char **) 0x1a6444 <argv0>
(gdb) s
Thread 1 received signal SIGSEGV, Segmentation fault.
main (argc=1, argv=0x22e3b0) at main.c:327
327 argv0 = argv[0];
(gdb) _
[3]
From src/z-util.c:
/**
* Convenient storage of the program name
*/
char *argv0 = NULL;