Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gprof report incomplete

15 views
Skip to first unread message

Ben Collver

unread,
Jul 31, 2022, 6:34:46 PM7/31/22
to
I am trying to use gprof in DJGPP 2.05. I wrote a small test program
named hello.c. On Linux, gprof correctly reports 10 calls to
function helloworld. With DJGPP, gprof reports an undefined number
of calls to __dpmi_int and nothing else.

I have included the program source and output below [1].

I reviewed the DJGPP FAQ chapter 13 to verify that i ran gprof
correctly. https://www.delorie.com/djgpp/v2faq/faq13_1.html

I am not sure how to troubleshoot this further. Any other ideas?

Thanks!
-Ben

[1]
bash-5.1$ cat hello.c
#include <stdio.h>

void helloworld(void) {
printf("hello world\r\n");
}

int main(int argc, char *argv[]) {
int i;
for (i = 0; i < 10; i++) {
helloworld();
}
}
bash-5.1$ gcc -pg -o hello hello.c
bash-5.1$ ./hello
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
bash-5.1$ gprof hello|head
Flat profile:

Each sample counts as 0.01 seconds.
no time accumulated

% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
0.00 0.00 0.00 10 0.00 0.00 helloworld
% the percentage of the total running time of the


C:\>gcc --version
gcc.exe (GCC) 7.2.0
...
C:\>gcc -pg -o hello.exe hello.c
C:\>hello.exe
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
C:\>gprof hello.exe | head
Flat profile:

Each sample counts as 0.0555556 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
100.00 0.11 0.11 __dpmi_int

% the percentage of the total running time of the
time program used by this function.
C:\>

Eli Zaretskii (eliz@gnu.org) [via djgpp@delorie.com]

unread,
Aug 1, 2022, 7:20:11 AM8/1/22
to dj...@delorie.com
> From: "Ben Collver (benco...@tilde.pink) [via dj...@delorie.com]" <dj...@delorie.com>
> Date: Sun, 31 Jul 2022 22:34:45 -0000 (UTC)
>
> I am trying to use gprof in DJGPP 2.05. I wrote a small test program
> named hello.c. On Linux, gprof correctly reports 10 calls to
> function helloworld. With DJGPP, gprof reports an undefined number
> of calls to __dpmi_int and nothing else.

I think this is more or less expected, given that (a) the profile
timer has a relatively low frequency in DJGPP (just 18.2 Hz), that
(b) the heavy processing of printf is in triggering switch from
protected mode to real mode and invoking a DOS interrupt (which
is what __dpmi_int does), and (c) that the profile timer is
effectively disabled during the time the CPU is in real mode.

> I am not sure how to troubleshoot this further. Any other ideas?

Why is it important to profile such toy programs? What real-life
problem did you encounter that led you to try the above?

Ben Collver

unread,
Aug 1, 2022, 11:25:15 AM8/1/22
to
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;
0 new messages