From b5fbb4c2b468bc776ba71e2c4ef692f095e034bd Mon Sep 17 00:00:00 2001 From: Vladimir Mezentsev Date: Thu, 11 May 2023 17:30:18 -0700 Subject: [PATCH] gprofng: include a new function in the right place Static function name is not available in stripped libraries. In this case, gprofng maps PC to a fake function like @0xPC (). Sometimes gprofng creates two functions instead of one. Also FUNC_FLAG_SIMULATED is needed for these fake functions. gprofng/ChangeLog 2023-05-11 Vladimir Mezentsev * src/LoadObject.cc (LoadObject::find_function): Set FUNC_FLAG_SIMULATED. Include a new function in the right place. --- gprofng/src/LoadObject.cc | 63 +++++++++++---------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/gprofng/src/LoadObject.cc b/gprofng/src/LoadObject.cc index f57db6001a9..9601dee7bd9 100644 --- a/gprofng/src/LoadObject.cc +++ b/gprofng/src/LoadObject.cc @@ -445,59 +445,31 @@ LoadObject::find_function (uint64_t foff) if (func == NULL) { int last = functions->size () - 1; - uint64_t usize = (uint64_t) size; - if (foff >= usize) + uint64_t usize = size < 0 ? 0 : (uint64_t) size; + if (last < 0) + high_bound = foff >= usize ? foff : usize; + else if (left == 0) + high_bound = functions->fetch (left)->img_offset; + else if (left < last) { - // Cannot map to this LoadObject. Probably LoadObject was changed. - if (last >= 0 && functions->fetch (last)->img_offset == usize) - { - // Function is already created - func = functions->fetch (last); - if (func->size < 0 || (uint64_t) func->size < foff - usize) - func->size = foff - usize; - } - else - { - low_bound = size; - high_bound = foff; - func_name = dbe_sprintf (GTXT ("@0x%llx (%s) -- no functions found"), - low_bound, name); - } - } - else if (last < 0) - { - low_bound = 0; - high_bound = size; - func_name = dbe_sprintf (GTXT ("@0x%llx (%s) -- no functions found"), - low_bound, name); - } - else if (foff < functions->fetch (0)->img_offset) - { - low_bound = 0; - high_bound = functions->fetch (0)->img_offset; + Function *fp = functions->fetch (left - 1); + low_bound = fp->img_offset + fp->size; + high_bound = functions->fetch (left)->img_offset; } else { Function *fp = functions->fetch (last); - if (foff >= fp->img_offset + fp->size) + if (fp->flags & FUNC_FLAG_SIMULATED) { - low_bound = fp->img_offset + fp->size; - high_bound = size; + // Function is already created + func = fp; + if (func->size < foff - func->img_offset) + func->size = foff - func->img_offset; } else { - fp = functions->fetch (left); - if (foff >= fp->img_offset + fp->size) - { - low_bound = fp->img_offset + fp->size; - high_bound = functions->fetch (left + 1)->img_offset; - } - else - { - Function *fp1 = functions->fetch (left - 1); - low_bound = fp1->img_offset + fp1->size; - high_bound = fp->img_offset; - } + low_bound = fp->img_offset + fp->size; + high_bound = foff > usize ? foff : usize; } } } @@ -505,6 +477,7 @@ LoadObject::find_function (uint64_t foff) if (func == NULL) { func = dbeSession->createFunction (); + func->flags |= FUNC_FLAG_SIMULATED; func->size = (unsigned) (high_bound - low_bound); func->module = noname; func->img_fname = get_pathname (); @@ -512,7 +485,7 @@ LoadObject::find_function (uint64_t foff) noname->functions->append (func); // unordered if (func_name == NULL) func_name = dbe_sprintf (GTXT ("@0x%llx (%s)"), low_bound, - name); + name); func->set_name (func_name); free (func_name); -- 2.30.2