Re: [PATCH v2] covoar: Store address-to-line info outside of DWARF

2021-06-17 Thread Chris Johns
On 17/6/21 1:01 pm, Alex White wrote:
> So is this ok to push now that it is known to have an insignificant 
> performance
> impact or is a different approach still warranted?

OK to push.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH v2] covoar: Store address-to-line info outside of DWARF

2021-06-16 Thread Alex White
On Mon, Jun 7, 2021 at 8:14 PM Chris Johns  wrote:
>
> On 8/6/21 1:44 am, Joel Sherrill wrote:
> >
> >
> > On Mon, Jun 7, 2021 at 7:00 AM Alex White  > > wrote:
> >
> >
> > On Wed, Jun 2, 2021 at 7:37 PM Chris Johns  > > wrote:
> > >
> > > Looking good with a single comment below ...
> > >
> > > On 3/6/21 6:08 am, Alex White wrote:
> > > > This adds the AddressToLineMapper class and supporting classes to
> > > > assume responsibility of tracking address-to-line information.
> > > >
> > > > This allows the DWARF library to properly cleanup all of its 
> > resources
> > > > and leads to significant memory savings.
> > > >
> > > > Closes #4383
> > > > ---
> > > >  rtemstoolkit/rld-dwarf.cpp   |   5 +
> > > >  rtemstoolkit/rld-dwarf.h |   5 +
> > > >  tester/covoar/AddressToLineMapper.cc | 104 +
> > > >  tester/covoar/AddressToLineMapper.h  | 211 
> > +++
> > > >  tester/covoar/ExecutableInfo.cc  |  73 +
> > > >  tester/covoar/ExecutableInfo.h   |  11 +-
> > > >  tester/covoar/wscript|   1 +
> > > >  7 files changed, 368 insertions(+), 42 deletions(-)
> > > >  create mode 100644 tester/covoar/AddressToLineMapper.cc
> > > >  create mode 100644 tester/covoar/AddressToLineMapper.h
> > > >
> > > > diff --git a/rtemstoolkit/rld-dwarf.cpp b/rtemstoolkit/rld-dwarf.cpp
> > > > index 2fce0e4..1eae50c 100644
> > > > --- a/rtemstoolkit/rld-dwarf.cpp
> > > > +++ b/rtemstoolkit/rld-dwarf.cpp
> > > > @@ -1893,6 +1893,11 @@ namespace rld
> > > >return false;
> > > >  }
> > > >
> > > > +const addresses& compilation_unit::get_addresses () const
> > > > +{
> > > > +  return addr_lines_;
> > > > +}
> > > > +
> > > >  functions&
> > > >  compilation_unit::get_functions ()
> > > >  {
> > > > diff --git a/rtemstoolkit/rld-dwarf.h b/rtemstoolkit/rld-dwarf.h
> > > > index 1210813..eadb50d 100644
> > > > --- a/rtemstoolkit/rld-dwarf.h
> > > > +++ b/rtemstoolkit/rld-dwarf.h
> > > > @@ -707,6 +707,11 @@ namespace rld
> > > > */
> > > >unsigned int pc_high () const;
> > > >
> > > > +  /**
> > > > +   * The addresses associated with this compilation unit.
> > > > +   */
> > > > +  const addresses& get_addresses () const;
> > > > +
> > > >/**
> > > > * Get the source and line for an address. If the address 
> > does
> > not match
> > > > * false is returned the file is set to 'unknown' and the 
> > line is
> > set to
> > > > diff --git a/tester/covoar/AddressToLineMapper.cc
> > b/tester/covoar/AddressToLineMapper.cc
> > > > new file mode 100644
> > > > index 000..c305e3b
> > > > --- /dev/null
> > > > +++ b/tester/covoar/AddressToLineMapper.cc
> > > > @@ -0,0 +1,104 @@
> > > > +/*! @file AddressToLineMapper.cc
> > > > + *  @brief AddressToLineMapper Implementation
> > > > + *
> > > > + *  This file contains the implementation of the functionality
> > > > + *  of the AddressToLineMapper class.
> > > > + */
> > > > +
> > > > +#include "AddressToLineMapper.h"
> > > > +
> > > > +namespace Coverage {
> > > > +
> > > > +  uint64_t SourceLine::location() const
> > > > +  {
> > > > +return address;
> > > > +  }
> > > > +
> > > > +  bool SourceLine::is_an_end_sequence() const
> > > > +  {
> > > > +return is_end_sequence;
> > > > +  }
> > > > +
> > > > +  const std::string& SourceLine::path() const
> > > > +  {
> > > > +return path_;
> > > > +  }
> > > > +
> > > > +  int SourceLine::line() const
> > > > +  {
> > > > +return line_num;
> > > > +  }
> > > > +
> > > > +  void AddressLineRange::addSourceLine(const rld::dwarf::address& 
> > address)
> > > > +  {
> > > > +auto insertResult = sourcePaths.insert(address.path());
> > > > +
> > > > +sourceLines.emplace_back(
> > > > +  SourceLine (
> > > > +address.location(),
> > > > +*insertResult.first,
> > > > +address.line(),
> > > > +address.is_an_end_sequence()
> > > > +  )
> > > > +);
> > > > +  }
> > > > +
> > > > +  const SourceLine& AddressLineRange::getSourceLine(uint32_t 
> > address) const
> > > > +  {
> > > > +if (address < lowAddress || address > highAddress) {
> > > > +  throw SourceNotFoundError(std::to_string(address));
> > > > +}
> > > > +
> > > > +const SourceLine* last_line = nullptr;
> > > > +for (const auto  : sourceLines) {
> > > > +  if (address <= line.location())
> > > > +  

Re: [PATCH v2] covoar: Store address-to-line info outside of DWARF

2021-06-07 Thread Chris Johns
On 8/6/21 1:44 am, Joel Sherrill wrote:
> 
> 
> On Mon, Jun 7, 2021 at 7:00 AM Alex White  > wrote:
> 
> 
> On Wed, Jun 2, 2021 at 7:37 PM Chris Johns  > wrote:
> >
> > Looking good with a single comment below ...
> >
> > On 3/6/21 6:08 am, Alex White wrote:
> > > This adds the AddressToLineMapper class and supporting classes to
> > > assume responsibility of tracking address-to-line information.
> > >
> > > This allows the DWARF library to properly cleanup all of its resources
> > > and leads to significant memory savings.
> > >
> > > Closes #4383
> > > ---
> > >  rtemstoolkit/rld-dwarf.cpp           |   5 +
> > >  rtemstoolkit/rld-dwarf.h             |   5 +
> > >  tester/covoar/AddressToLineMapper.cc | 104 +
> > >  tester/covoar/AddressToLineMapper.h  | 211 
> +++
> > >  tester/covoar/ExecutableInfo.cc      |  73 +
> > >  tester/covoar/ExecutableInfo.h       |  11 +-
> > >  tester/covoar/wscript                |   1 +
> > >  7 files changed, 368 insertions(+), 42 deletions(-)
> > >  create mode 100644 tester/covoar/AddressToLineMapper.cc
> > >  create mode 100644 tester/covoar/AddressToLineMapper.h
> > >
> > > diff --git a/rtemstoolkit/rld-dwarf.cpp b/rtemstoolkit/rld-dwarf.cpp
> > > index 2fce0e4..1eae50c 100644
> > > --- a/rtemstoolkit/rld-dwarf.cpp
> > > +++ b/rtemstoolkit/rld-dwarf.cpp
> > > @@ -1893,6 +1893,11 @@ namespace rld
> > >        return false;
> > >      }
> > >
> > > +    const addresses& compilation_unit::get_addresses () const
> > > +    {
> > > +      return addr_lines_;
> > > +    }
> > > +
> > >      functions&
> > >      compilation_unit::get_functions ()
> > >      {
> > > diff --git a/rtemstoolkit/rld-dwarf.h b/rtemstoolkit/rld-dwarf.h
> > > index 1210813..eadb50d 100644
> > > --- a/rtemstoolkit/rld-dwarf.h
> > > +++ b/rtemstoolkit/rld-dwarf.h
> > > @@ -707,6 +707,11 @@ namespace rld
> > >         */
> > >        unsigned int pc_high () const;
> > >
> > > +      /**
> > > +       * The addresses associated with this compilation unit.
> > > +       */
> > > +      const addresses& get_addresses () const;
> > > +
> > >        /**
> > >         * Get the source and line for an address. If the address does
> not match
> > >         * false is returned the file is set to 'unknown' and the line 
> is
> set to
> > > diff --git a/tester/covoar/AddressToLineMapper.cc
> b/tester/covoar/AddressToLineMapper.cc
> > > new file mode 100644
> > > index 000..c305e3b
> > > --- /dev/null
> > > +++ b/tester/covoar/AddressToLineMapper.cc
> > > @@ -0,0 +1,104 @@
> > > +/*! @file AddressToLineMapper.cc
> > > + *  @brief AddressToLineMapper Implementation
> > > + *
> > > + *  This file contains the implementation of the functionality
> > > + *  of the AddressToLineMapper class.
> > > + */
> > > +
> > > +#include "AddressToLineMapper.h"
> > > +
> > > +namespace Coverage {
> > > +
> > > +  uint64_t SourceLine::location() const
> > > +  {
> > > +    return address;
> > > +  }
> > > +
> > > +  bool SourceLine::is_an_end_sequence() const
> > > +  {
> > > +    return is_end_sequence;
> > > +  }
> > > +
> > > +  const std::string& SourceLine::path() const
> > > +  {
> > > +    return path_;
> > > +  }
> > > +
> > > +  int SourceLine::line() const
> > > +  {
> > > +    return line_num;
> > > +  }
> > > +
> > > +  void AddressLineRange::addSourceLine(const rld::dwarf::address& 
> address)
> > > +  {
> > > +    auto insertResult = sourcePaths.insert(address.path());
> > > +
> > > +    sourceLines.emplace_back(
> > > +      SourceLine (
> > > +        address.location(),
> > > +        *insertResult.first,
> > > +        address.line(),
> > > +        address.is_an_end_sequence()
> > > +      )
> > > +    );
> > > +  }
> > > +
> > > +  const SourceLine& AddressLineRange::getSourceLine(uint32_t 
> address) const
> > > +  {
> > > +    if (address < lowAddress || address > highAddress) {
> > > +      throw SourceNotFoundError(std::to_string(address));
> > > +    }
> > > +
> > > +    const SourceLine* last_line = nullptr;
> > > +    for (const auto  : sourceLines) {
> > > +      if (address <= line.location())
> > > +      {
> > > +        if (address == line.location())
> > > +          last_line = 
> > > +        break;
> > > +      }
> > > +      last_line = 
> > > +    }
> > > +
> > > +    if (last_line == nullptr) {
> > > +      throw SourceNotFoundError(std::to_string(address));
> > > +    }
>   

Re: [PATCH v2] covoar: Store address-to-line info outside of DWARF

2021-06-07 Thread Joel Sherrill
On Mon, Jun 7, 2021 at 7:00 AM Alex White  wrote:

>
> On Wed, Jun 2, 2021 at 7:37 PM Chris Johns  wrote:
> >
> > Looking good with a single comment below ...
> >
> > On 3/6/21 6:08 am, Alex White wrote:
> > > This adds the AddressToLineMapper class and supporting classes to
> > > assume responsibility of tracking address-to-line information.
> > >
> > > This allows the DWARF library to properly cleanup all of its resources
> > > and leads to significant memory savings.
> > >
> > > Closes #4383
> > > ---
> > >  rtemstoolkit/rld-dwarf.cpp   |   5 +
> > >  rtemstoolkit/rld-dwarf.h |   5 +
> > >  tester/covoar/AddressToLineMapper.cc | 104 +
> > >  tester/covoar/AddressToLineMapper.h  | 211 +++
> > >  tester/covoar/ExecutableInfo.cc  |  73 +
> > >  tester/covoar/ExecutableInfo.h   |  11 +-
> > >  tester/covoar/wscript|   1 +
> > >  7 files changed, 368 insertions(+), 42 deletions(-)
> > >  create mode 100644 tester/covoar/AddressToLineMapper.cc
> > >  create mode 100644 tester/covoar/AddressToLineMapper.h
> > >
> > > diff --git a/rtemstoolkit/rld-dwarf.cpp b/rtemstoolkit/rld-dwarf.cpp
> > > index 2fce0e4..1eae50c 100644
> > > --- a/rtemstoolkit/rld-dwarf.cpp
> > > +++ b/rtemstoolkit/rld-dwarf.cpp
> > > @@ -1893,6 +1893,11 @@ namespace rld
> > >return false;
> > >  }
> > >
> > > +const addresses& compilation_unit::get_addresses () const
> > > +{
> > > +  return addr_lines_;
> > > +}
> > > +
> > >  functions&
> > >  compilation_unit::get_functions ()
> > >  {
> > > diff --git a/rtemstoolkit/rld-dwarf.h b/rtemstoolkit/rld-dwarf.h
> > > index 1210813..eadb50d 100644
> > > --- a/rtemstoolkit/rld-dwarf.h
> > > +++ b/rtemstoolkit/rld-dwarf.h
> > > @@ -707,6 +707,11 @@ namespace rld
> > > */
> > >unsigned int pc_high () const;
> > >
> > > +  /**
> > > +   * The addresses associated with this compilation unit.
> > > +   */
> > > +  const addresses& get_addresses () const;
> > > +
> > >/**
> > > * Get the source and line for an address. If the address does
> not match
> > > * false is returned the file is set to 'unknown' and the line
> is set to
> > > diff --git a/tester/covoar/AddressToLineMapper.cc
> b/tester/covoar/AddressToLineMapper.cc
> > > new file mode 100644
> > > index 000..c305e3b
> > > --- /dev/null
> > > +++ b/tester/covoar/AddressToLineMapper.cc
> > > @@ -0,0 +1,104 @@
> > > +/*! @file AddressToLineMapper.cc
> > > + *  @brief AddressToLineMapper Implementation
> > > + *
> > > + *  This file contains the implementation of the functionality
> > > + *  of the AddressToLineMapper class.
> > > + */
> > > +
> > > +#include "AddressToLineMapper.h"
> > > +
> > > +namespace Coverage {
> > > +
> > > +  uint64_t SourceLine::location() const
> > > +  {
> > > +return address;
> > > +  }
> > > +
> > > +  bool SourceLine::is_an_end_sequence() const
> > > +  {
> > > +return is_end_sequence;
> > > +  }
> > > +
> > > +  const std::string& SourceLine::path() const
> > > +  {
> > > +return path_;
> > > +  }
> > > +
> > > +  int SourceLine::line() const
> > > +  {
> > > +return line_num;
> > > +  }
> > > +
> > > +  void AddressLineRange::addSourceLine(const rld::dwarf::address&
> address)
> > > +  {
> > > +auto insertResult = sourcePaths.insert(address.path());
> > > +
> > > +sourceLines.emplace_back(
> > > +  SourceLine (
> > > +address.location(),
> > > +*insertResult.first,
> > > +address.line(),
> > > +address.is_an_end_sequence()
> > > +  )
> > > +);
> > > +  }
> > > +
> > > +  const SourceLine& AddressLineRange::getSourceLine(uint32_t address)
> const
> > > +  {
> > > +if (address < lowAddress || address > highAddress) {
> > > +  throw SourceNotFoundError(std::to_string(address));
> > > +}
> > > +
> > > +const SourceLine* last_line = nullptr;
> > > +for (const auto  : sourceLines) {
> > > +  if (address <= line.location())
> > > +  {
> > > +if (address == line.location())
> > > +  last_line = 
> > > +break;
> > > +  }
> > > +  last_line = 
> > > +}
> > > +
> > > +if (last_line == nullptr) {
> > > +  throw SourceNotFoundError(std::to_string(address));
> > > +}
> > > +
> > > +return *last_line;
> > > +  }
> >
> > How often is this function being called? If it is a hot spot are there
> other
> > ways to search for the address? I suppose it depends on the number of
> lines in
> > the vector.
>
> According to a quick gprof run, this function is being called a decent
> amount, somewhere around 1.5 million times for a full ARM coverage run.
>
> But it only takes up a very small amount (less than 0.02%) of cumulative
> execution time so I don't believe it is an issue.
>

Glad we have profiling data to guide optimizations. I also suspect that as
the code is c-plus-plus-ified more, some performance 

Re: [PATCH v2] covoar: Store address-to-line info outside of DWARF

2021-06-07 Thread Alex White

On Wed, Jun 2, 2021 at 7:37 PM Chris Johns  wrote:
>
> Looking good with a single comment below ...
>
> On 3/6/21 6:08 am, Alex White wrote:
> > This adds the AddressToLineMapper class and supporting classes to
> > assume responsibility of tracking address-to-line information.
> >
> > This allows the DWARF library to properly cleanup all of its resources
> > and leads to significant memory savings.
> >
> > Closes #4383
> > ---
> >  rtemstoolkit/rld-dwarf.cpp   |   5 +
> >  rtemstoolkit/rld-dwarf.h |   5 +
> >  tester/covoar/AddressToLineMapper.cc | 104 +
> >  tester/covoar/AddressToLineMapper.h  | 211 +++
> >  tester/covoar/ExecutableInfo.cc  |  73 +
> >  tester/covoar/ExecutableInfo.h   |  11 +-
> >  tester/covoar/wscript|   1 +
> >  7 files changed, 368 insertions(+), 42 deletions(-)
> >  create mode 100644 tester/covoar/AddressToLineMapper.cc
> >  create mode 100644 tester/covoar/AddressToLineMapper.h
> >
> > diff --git a/rtemstoolkit/rld-dwarf.cpp b/rtemstoolkit/rld-dwarf.cpp
> > index 2fce0e4..1eae50c 100644
> > --- a/rtemstoolkit/rld-dwarf.cpp
> > +++ b/rtemstoolkit/rld-dwarf.cpp
> > @@ -1893,6 +1893,11 @@ namespace rld
> >return false;
> >  }
> >
> > +const addresses& compilation_unit::get_addresses () const
> > +{
> > +  return addr_lines_;
> > +}
> > +
> >  functions&
> >  compilation_unit::get_functions ()
> >  {
> > diff --git a/rtemstoolkit/rld-dwarf.h b/rtemstoolkit/rld-dwarf.h
> > index 1210813..eadb50d 100644
> > --- a/rtemstoolkit/rld-dwarf.h
> > +++ b/rtemstoolkit/rld-dwarf.h
> > @@ -707,6 +707,11 @@ namespace rld
> > */
> >unsigned int pc_high () const;
> >
> > +  /**
> > +   * The addresses associated with this compilation unit.
> > +   */
> > +  const addresses& get_addresses () const;
> > +
> >/**
> > * Get the source and line for an address. If the address does not 
> > match
> > * false is returned the file is set to 'unknown' and the line is 
> > set to
> > diff --git a/tester/covoar/AddressToLineMapper.cc 
> > b/tester/covoar/AddressToLineMapper.cc
> > new file mode 100644
> > index 000..c305e3b
> > --- /dev/null
> > +++ b/tester/covoar/AddressToLineMapper.cc
> > @@ -0,0 +1,104 @@
> > +/*! @file AddressToLineMapper.cc
> > + *  @brief AddressToLineMapper Implementation
> > + *
> > + *  This file contains the implementation of the functionality
> > + *  of the AddressToLineMapper class.
> > + */
> > +
> > +#include "AddressToLineMapper.h"
> > +
> > +namespace Coverage {
> > +
> > +  uint64_t SourceLine::location() const
> > +  {
> > +return address;
> > +  }
> > +
> > +  bool SourceLine::is_an_end_sequence() const
> > +  {
> > +return is_end_sequence;
> > +  }
> > +
> > +  const std::string& SourceLine::path() const
> > +  {
> > +return path_;
> > +  }
> > +
> > +  int SourceLine::line() const
> > +  {
> > +return line_num;
> > +  }
> > +
> > +  void AddressLineRange::addSourceLine(const rld::dwarf::address& address)
> > +  {
> > +auto insertResult = sourcePaths.insert(address.path());
> > +
> > +sourceLines.emplace_back(
> > +  SourceLine (
> > +address.location(),
> > +*insertResult.first,
> > +address.line(),
> > +address.is_an_end_sequence()
> > +  )
> > +);
> > +  }
> > +
> > +  const SourceLine& AddressLineRange::getSourceLine(uint32_t address) const
> > +  {
> > +if (address < lowAddress || address > highAddress) {
> > +  throw SourceNotFoundError(std::to_string(address));
> > +}
> > +
> > +const SourceLine* last_line = nullptr;
> > +for (const auto  : sourceLines) {
> > +  if (address <= line.location())
> > +  {
> > +if (address == line.location())
> > +  last_line = 
> > +break;
> > +  }
> > +  last_line = 
> > +}
> > +
> > +if (last_line == nullptr) {
> > +  throw SourceNotFoundError(std::to_string(address));
> > +}
> > +
> > +return *last_line;
> > +  }
>
> How often is this function being called? If it is a hot spot are there other
> ways to search for the address? I suppose it depends on the number of lines in
> the vector.

According to a quick gprof run, this function is being called a decent amount, 
somewhere around 1.5 million times for a full ARM coverage run.

But it only takes up a very small amount (less than 0.02%) of cumulative 
execution time so I don't believe it is an issue.

Alex

>
> If the sourcesLines vector was sorted can this loop be replaced with some form
> of std::upper_bound? That is ...
>
>  auto last_line =
> std::upper_bound(sourceLines.begin(),
>  sourceLines.end(),
>  address,
>  [](const SourceLine& sl) {
>return address < sl.location();
>  });
>
> [ not sure if the code I posted would work and if I got 

Re: [PATCH v2] covoar: Store address-to-line info outside of DWARF

2021-06-02 Thread Chris Johns
Looking good with a single comment below ...

On 3/6/21 6:08 am, Alex White wrote:
> This adds the AddressToLineMapper class and supporting classes to
> assume responsibility of tracking address-to-line information.
> 
> This allows the DWARF library to properly cleanup all of its resources
> and leads to significant memory savings.
> 
> Closes #4383
> ---
>  rtemstoolkit/rld-dwarf.cpp   |   5 +
>  rtemstoolkit/rld-dwarf.h |   5 +
>  tester/covoar/AddressToLineMapper.cc | 104 +
>  tester/covoar/AddressToLineMapper.h  | 211 +++
>  tester/covoar/ExecutableInfo.cc  |  73 +
>  tester/covoar/ExecutableInfo.h   |  11 +-
>  tester/covoar/wscript|   1 +
>  7 files changed, 368 insertions(+), 42 deletions(-)
>  create mode 100644 tester/covoar/AddressToLineMapper.cc
>  create mode 100644 tester/covoar/AddressToLineMapper.h
> 
> diff --git a/rtemstoolkit/rld-dwarf.cpp b/rtemstoolkit/rld-dwarf.cpp
> index 2fce0e4..1eae50c 100644
> --- a/rtemstoolkit/rld-dwarf.cpp
> +++ b/rtemstoolkit/rld-dwarf.cpp
> @@ -1893,6 +1893,11 @@ namespace rld
>return false;
>  }
>  
> +const addresses& compilation_unit::get_addresses () const
> +{
> +  return addr_lines_;
> +}
> +
>  functions&
>  compilation_unit::get_functions ()
>  {
> diff --git a/rtemstoolkit/rld-dwarf.h b/rtemstoolkit/rld-dwarf.h
> index 1210813..eadb50d 100644
> --- a/rtemstoolkit/rld-dwarf.h
> +++ b/rtemstoolkit/rld-dwarf.h
> @@ -707,6 +707,11 @@ namespace rld
> */
>unsigned int pc_high () const;
>  
> +  /**
> +   * The addresses associated with this compilation unit.
> +   */
> +  const addresses& get_addresses () const;
> +
>/**
> * Get the source and line for an address. If the address does not 
> match
> * false is returned the file is set to 'unknown' and the line is set 
> to
> diff --git a/tester/covoar/AddressToLineMapper.cc 
> b/tester/covoar/AddressToLineMapper.cc
> new file mode 100644
> index 000..c305e3b
> --- /dev/null
> +++ b/tester/covoar/AddressToLineMapper.cc
> @@ -0,0 +1,104 @@
> +/*! @file AddressToLineMapper.cc
> + *  @brief AddressToLineMapper Implementation
> + *
> + *  This file contains the implementation of the functionality
> + *  of the AddressToLineMapper class.
> + */
> +
> +#include "AddressToLineMapper.h"
> +
> +namespace Coverage {
> +
> +  uint64_t SourceLine::location() const
> +  {
> +return address;
> +  }
> +
> +  bool SourceLine::is_an_end_sequence() const
> +  {
> +return is_end_sequence;
> +  }
> +
> +  const std::string& SourceLine::path() const
> +  {
> +return path_;
> +  }
> +
> +  int SourceLine::line() const
> +  {
> +return line_num;
> +  }
> +
> +  void AddressLineRange::addSourceLine(const rld::dwarf::address& address)
> +  {
> +auto insertResult = sourcePaths.insert(address.path());
> +
> +sourceLines.emplace_back(
> +  SourceLine (
> +address.location(),
> +*insertResult.first,
> +address.line(),
> +address.is_an_end_sequence()
> +  )
> +);
> +  }
> +
> +  const SourceLine& AddressLineRange::getSourceLine(uint32_t address) const
> +  {
> +if (address < lowAddress || address > highAddress) {
> +  throw SourceNotFoundError(std::to_string(address));
> +}
> +
> +const SourceLine* last_line = nullptr;
> +for (const auto  : sourceLines) {
> +  if (address <= line.location())
> +  {
> +if (address == line.location())
> +  last_line = 
> +break;
> +  }
> +  last_line = 
> +}
> +
> +if (last_line == nullptr) {
> +  throw SourceNotFoundError(std::to_string(address));
> +}
> +
> +return *last_line;
> +  }

How often is this function being called? If it is a hot spot are there other
ways to search for the address? I suppose it depends on the number of lines in
the vector.

If the sourcesLines vector was sorted can this loop be replaced with some form
of std::upper_bound? That is ...

 auto last_line =
std::upper_bound(sourceLines.begin(),
 sourceLines.end(),
 address,
 [](const SourceLine& sl) {
   return address < sl.location();
 });

[ not sure if the code I posted would work and if I got the lamda right :) ]

Just wondering.

Chris

> +
> +  void AddressToLineMapper::getSource(
> +uint32_t address,
> +std::string& sourceFile,
> +int& sourceLine
> +  ) const {
> +const SourceLine default_sourceline = SourceLine();
> +const SourceLine* match = _sourceline;
> +
> +for (const auto  : addressLineRanges) {
> +  try {
> +const SourceLine& potential_match = range.getSourceLine(address);
> +
> +if (match->is_an_end_sequence() || 
> !potential_match.is_an_end_sequence()) {
> +  match = _match;
> +}
> +  } catch (const 

[PATCH v2] covoar: Store address-to-line info outside of DWARF

2021-06-02 Thread Alex White
This adds the AddressToLineMapper class and supporting classes to
assume responsibility of tracking address-to-line information.

This allows the DWARF library to properly cleanup all of its resources
and leads to significant memory savings.

Closes #4383
---
 rtemstoolkit/rld-dwarf.cpp   |   5 +
 rtemstoolkit/rld-dwarf.h |   5 +
 tester/covoar/AddressToLineMapper.cc | 104 +
 tester/covoar/AddressToLineMapper.h  | 211 +++
 tester/covoar/ExecutableInfo.cc  |  73 +
 tester/covoar/ExecutableInfo.h   |  11 +-
 tester/covoar/wscript|   1 +
 7 files changed, 368 insertions(+), 42 deletions(-)
 create mode 100644 tester/covoar/AddressToLineMapper.cc
 create mode 100644 tester/covoar/AddressToLineMapper.h

diff --git a/rtemstoolkit/rld-dwarf.cpp b/rtemstoolkit/rld-dwarf.cpp
index 2fce0e4..1eae50c 100644
--- a/rtemstoolkit/rld-dwarf.cpp
+++ b/rtemstoolkit/rld-dwarf.cpp
@@ -1893,6 +1893,11 @@ namespace rld
   return false;
 }
 
+const addresses& compilation_unit::get_addresses () const
+{
+  return addr_lines_;
+}
+
 functions&
 compilation_unit::get_functions ()
 {
diff --git a/rtemstoolkit/rld-dwarf.h b/rtemstoolkit/rld-dwarf.h
index 1210813..eadb50d 100644
--- a/rtemstoolkit/rld-dwarf.h
+++ b/rtemstoolkit/rld-dwarf.h
@@ -707,6 +707,11 @@ namespace rld
*/
   unsigned int pc_high () const;
 
+  /**
+   * The addresses associated with this compilation unit.
+   */
+  const addresses& get_addresses () const;
+
   /**
* Get the source and line for an address. If the address does not match
* false is returned the file is set to 'unknown' and the line is set to
diff --git a/tester/covoar/AddressToLineMapper.cc 
b/tester/covoar/AddressToLineMapper.cc
new file mode 100644
index 000..c305e3b
--- /dev/null
+++ b/tester/covoar/AddressToLineMapper.cc
@@ -0,0 +1,104 @@
+/*! @file AddressToLineMapper.cc
+ *  @brief AddressToLineMapper Implementation
+ *
+ *  This file contains the implementation of the functionality
+ *  of the AddressToLineMapper class.
+ */
+
+#include "AddressToLineMapper.h"
+
+namespace Coverage {
+
+  uint64_t SourceLine::location() const
+  {
+return address;
+  }
+
+  bool SourceLine::is_an_end_sequence() const
+  {
+return is_end_sequence;
+  }
+
+  const std::string& SourceLine::path() const
+  {
+return path_;
+  }
+
+  int SourceLine::line() const
+  {
+return line_num;
+  }
+
+  void AddressLineRange::addSourceLine(const rld::dwarf::address& address)
+  {
+auto insertResult = sourcePaths.insert(address.path());
+
+sourceLines.emplace_back(
+  SourceLine (
+address.location(),
+*insertResult.first,
+address.line(),
+address.is_an_end_sequence()
+  )
+);
+  }
+
+  const SourceLine& AddressLineRange::getSourceLine(uint32_t address) const
+  {
+if (address < lowAddress || address > highAddress) {
+  throw SourceNotFoundError(std::to_string(address));
+}
+
+const SourceLine* last_line = nullptr;
+for (const auto  : sourceLines) {
+  if (address <= line.location())
+  {
+if (address == line.location())
+  last_line = 
+break;
+  }
+  last_line = 
+}
+
+if (last_line == nullptr) {
+  throw SourceNotFoundError(std::to_string(address));
+}
+
+return *last_line;
+  }
+
+  void AddressToLineMapper::getSource(
+uint32_t address,
+std::string& sourceFile,
+int& sourceLine
+  ) const {
+const SourceLine default_sourceline = SourceLine();
+const SourceLine* match = _sourceline;
+
+for (const auto  : addressLineRanges) {
+  try {
+const SourceLine& potential_match = range.getSourceLine(address);
+
+if (match->is_an_end_sequence() || 
!potential_match.is_an_end_sequence()) {
+  match = _match;
+}
+  } catch (const AddressLineRange::SourceNotFoundError&) {}
+}
+
+sourceFile = match->path();
+sourceLine = match->line();
+  }
+
+  AddressLineRange& AddressToLineMapper::makeRange(
+uint32_t low,
+uint32_t high
+  )
+  {
+addressLineRanges.emplace_back(
+  AddressLineRange(low, high)
+);
+
+return addressLineRanges.back();
+  }
+
+}
diff --git a/tester/covoar/AddressToLineMapper.h 
b/tester/covoar/AddressToLineMapper.h
new file mode 100644
index 000..e6ab4a8
--- /dev/null
+++ b/tester/covoar/AddressToLineMapper.h
@@ -0,0 +1,211 @@
+/*! @file AddressToLineMapper.h
+ *  @brief AddressToLineMapper Specification
+ *
+ *  This file contains the specification of the AddressToLineMapper class.
+ */
+
+#ifndef __ADDRESS_TO_LINE_MAPPER_H__
+#define __ADDRESS_TO_LINE_MAPPER_H__
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+namespace Coverage {
+
+  /*! @class SourceLine
+   *
+   *  This class stores source information for a specific address.
+   */
+  class SourceLine {
+
+  public:
+
+