From 645659b05cb4cb47b5d980cd2f527fafe4067830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrea=20Palmat=C3=A8?= Date: Wed, 20 Sep 2023 08:46:56 +0200 Subject: [PATCH] Messing around.. --- GNUmakefile.os4 | 2 +- library/profile/_mcount.c | 17 ++++++++------- library/profile/gmon.c | 46 +++++++++++++++++++++++++++++---------- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/GNUmakefile.os4 b/GNUmakefile.os4 index b24a75af..68552210 100644 --- a/GNUmakefile.os4 +++ b/GNUmakefile.os4 @@ -63,7 +63,7 @@ WARNINGS := \ -Wundef -Wmissing-declarations -Wunused -Wwrite-strings -Wno-unused-value -Wno-comment -Wno-missing-braces \ -Wno-deprecated-declarations -Wno-sign-compare -Wno-unused-variable -Wno-parentheses -Wno-missing-prototypes \ -Wstrict-aliasing -Wno-shadow -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing \ - -Wno-type-limits -Wno-cast-function-type -Werror # -Wbad-function-cast -Wconversion -Wformat + -Wno-type-limits -Wno-cast-function-type -Wno-frame-address -Werror # -Wbad-function-cast -Wconversion -Wformat PIC := -fPIC -DPIC INCLUDES := -I$(LIB_DIR)/include \ diff --git a/library/profile/_mcount.c b/library/profile/_mcount.c index ab67d01f..fcabeeeb 100644 --- a/library/profile/_mcount.c +++ b/library/profile/_mcount.c @@ -30,11 +30,14 @@ __mcount(uint32 frompc, uint32 selfpc) { * Check if the PC is inside our text segment. * Really should be... */ + dprintf("p->textsize %x\n", p->textsize); + dprintf("p->lowpc %x\n", p->lowpc); + dprintf("frompc1 %x\n", frompc); + dprintf("selfpc1 %x\n", selfpc); frompc -= p->lowpc; selfpc -= p->lowpc; - dprintf("frompc %d\n", frompc); - dprintf("p->textsize %d\n", p->textsize); - dprintf("selfpc %d\n", selfpc); + dprintf("frompc2 %x\n", frompc); + dprintf("selfpc2 %x\n", selfpc); if (frompc > p->textsize) goto done; @@ -71,11 +74,9 @@ __mcount(uint32 frompc, uint32 selfpc) { goto done; } top = &p->tos[toindex]; - printf("top->selfpc = %d - selfpc = %d\n", top->selfpc, selfpc); + printf("p->lowpc = %p - top->selfpc = %x - selfpc = %x\n", p->lowpc, top->selfpc, selfpc); if (top->selfpc == selfpc) { - /* - * arc at front of chain; usual case. - */ + /* arc at front of chain; usual case. */ top->count++; goto done; } @@ -85,7 +86,7 @@ __mcount(uint32 frompc, uint32 selfpc) { * prevtop points to previous top. * we know it is not at the head of the chain. */ - for (; /* goto done */; ) { + for (;; ) { if (top->link == 0) { /* * top is end of the chain and none of the chain diff --git a/library/profile/gmon.c b/library/profile/gmon.c index 2d14a53e..6da2d99a 100644 --- a/library/profile/gmon.c +++ b/library/profile/gmon.c @@ -32,6 +32,7 @@ void write_hist(int fd) { u_char tag = GMON_TAG_TIME_HIST; + printf("_gmonparam.kcountsize = %d\n", _gmonparam.kcountsize); if (_gmonparam.kcountsize > 0) { struct iovec iov[3] = { { &tag, sizeof(tag) }, @@ -39,11 +40,19 @@ write_hist(int fd) { { _gmonparam.kcount, _gmonparam.kcountsize } }; - if (sizeof(thdr) != sizeof(struct gmon_hist_hdr) || (offsetof(struct real_gmon_hist_hdr, low_pc) != offsetof(struct gmon_hist_hdr, low_pc)) || (offsetof(struct real_gmon_hist_hdr, high_pc) != offsetof(struct gmon_hist_hdr, high_pc)) || (offsetof(struct real_gmon_hist_hdr, hist_size) != offsetof(struct gmon_hist_hdr, hist_size)) || (offsetof(struct real_gmon_hist_hdr, prof_rate) != offsetof(struct gmon_hist_hdr, prof_rate)) || (offsetof(struct real_gmon_hist_hdr, dimen) != offsetof(struct gmon_hist_hdr, dimen)) || (offsetof(struct real_gmon_hist_hdr, dimen_abbrev) != offsetof(struct gmon_hist_hdr, dimen_abbrev))) + if ( + sizeof(thdr) != sizeof(struct gmon_hist_hdr) || + (offsetof(struct real_gmon_hist_hdr, low_pc) != offsetof(struct gmon_hist_hdr, low_pc)) || + (offsetof(struct real_gmon_hist_hdr, high_pc) != offsetof(struct gmon_hist_hdr, high_pc)) || + (offsetof(struct real_gmon_hist_hdr, hist_size) != offsetof(struct gmon_hist_hdr, hist_size)) || + (offsetof(struct real_gmon_hist_hdr, prof_rate) != offsetof(struct gmon_hist_hdr, prof_rate)) || + (offsetof(struct real_gmon_hist_hdr, dimen) != offsetof(struct gmon_hist_hdr, dimen)) || + (offsetof(struct real_gmon_hist_hdr, dimen_abbrev) != offsetof(struct gmon_hist_hdr, dimen_abbrev)) + ) return; - thdr.low_pc = (char *)_gmonparam.lowpc; - thdr.high_pc = (char *)_gmonparam.highpc; + thdr.low_pc = (char *) _gmonparam.lowpc; + thdr.high_pc = (char *) _gmonparam.highpc; thdr.hist_size = _gmonparam.kcountsize / sizeof(HISTCOUNTER); printf("hist_size = %d - _gmonparam.kcountsize = %d - sizeof(HISTCOUNTER) = %d\n", thdr.hist_size, _gmonparam.kcountsize, sizeof(HISTCOUNTER)); @@ -80,7 +89,8 @@ write_call_graph(int fd) { continue; /* FIXME: was p->lowpc; needs to be 0 and assumes -Ttext=0 on compile. Better idea? */ - frompc = 0; //_gmonparam.lowpc; + printf("_gmonparam.lowpc = %x\n", _gmonparam.lowpc); + frompc = _gmonparam.lowpc; frompc += (from_index * _gmonparam.hashfraction * sizeof(*_gmonparam.froms)); for (to_index = _gmonparam.froms[from_index]; to_index != 0; @@ -94,7 +104,7 @@ write_call_graph(int fd) { arc.frompc = (char *)frompc; arc.selfpc = (char *)_gmonparam.tos[to_index].selfpc; arc.count = _gmonparam.tos[to_index].count; - printf("arc.count = %d\n", arc.count); + printf("arc.frompc = %x - _gmonparam.tos[to_index].selfpc = %x\n", arc.frompc, _gmonparam.tos[to_index].selfpc); memcpy(raw_arc + nfilled, &arc, sizeof(raw_arc[0])); if (++nfilled == NARCS_PER_WRITEV) { @@ -152,7 +162,7 @@ void monstartup(uint32 low_pc, uint32 high_pc) { struct gmonparam *p = &_gmonparam; register int o; - dprintf("in monstartup)\n"); + dprintf("in monstartup low_pc = %d - high_pc = %d\n", low_pc, high_pc); /* * If we don't get proper lowpc and highpc, then @@ -268,32 +278,36 @@ void moncontrol(int mode) { } void moncleanup(void) { - BPTR fd; + int fd; struct gmonparam *p = &_gmonparam; moncontrol(0); if (p->state == kGmonProfError) { fprintf(stderr, "WARNING: Overflow during profiling\n"); + goto out; } if (_gmonparam.kcountsize > 0) { fd = open("gmon.out", O_CREAT | O_TRUNC | O_WRONLY); if (!fd) { fprintf(stderr, "ERROR: could not open gmon.out\n"); - return; + goto out; } /* write gmon.out header: */ - struct real_gmon_hdr - { + struct real_gmon_hdr { char cookie[4]; int32_t version; char spare[3 * 4]; } ghdr; - if (sizeof(ghdr) != sizeof(struct gmon_hdr) || (offsetof(struct real_gmon_hdr, cookie) != offsetof(struct gmon_hdr, cookie)) || (offsetof(struct real_gmon_hdr, version) != offsetof(struct gmon_hdr, version))) - return; + if ( + sizeof(ghdr) != sizeof(struct gmon_hdr) || + (offsetof(struct real_gmon_hdr, cookie) != offsetof(struct gmon_hdr, cookie)) || + (offsetof(struct real_gmon_hdr, version) != offsetof(struct gmon_hdr, version))) { + goto out; + } memcpy(&ghdr.cookie[0], GMON_MAGIC, sizeof(ghdr.cookie)); ghdr.version = GMON_VERSION; @@ -311,6 +325,12 @@ void moncleanup(void) { close(fd); } +out: + if (p->tos) { + FreeVec(p->tos); + p->tos = NULL; + } + } void mongetpcs(uint32 *lowpc, uint32 *highpc) { @@ -344,6 +364,8 @@ void mongetpcs(uint32 *lowpc, uint32 *highpc) { uint32 base = (uint32) GetSectionTags(elfHandle, GST_SectionIndex, i, TAG_DONE); *lowpc = base; *highpc = base + shdr->sh_size; + printf("LOWPC = %x\n", lowpc); + printf("HIGHPC = %x\n", highpc); break; } }