Re: [PATCH rtems-tools v1 02/10] covoar.cc: Convert to C++

2021-09-09 Thread Chris Johns
On 10/9/21 12:17 am, Ryan Long wrote:
> ExecutableInfo takes a const char* const parameter and initializes a string. 
> I tried to take off the c_str(), but it wouldn't build then. Is it alright 
> for that to temporarily stay there until I make a sweep through 
> ExecutableInfo.cc? Or do you want me to go ahead and do that, and add it to 
> this patchset?

Yes of course. I am just wanting to help with some simple and hopefully cheap
changes.

> I was able to remove the c_str() from the CoverageFormatToEnum() call though.

Great.

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


RE: [PATCH rtems-tools v1 02/10] covoar.cc: Convert to C++

2021-09-09 Thread Ryan Long
ExecutableInfo takes a const char* const parameter and initializes a string. I 
tried to take off the c_str(), but it wouldn't build then. Is it alright for 
that to temporarily stay there until I make a sweep through ExecutableInfo.cc? 
Or do you want me to go ahead and do that, and add it to this patchset?

I was able to remove the c_str() from the CoverageFormatToEnum() call though.

-Original Message-
From: devel  On Behalf Of Chris Johns
Sent: Wednesday, September 8, 2021 5:46 PM
To: devel@rtems.org
Subject: Re: [PATCH rtems-tools v1 02/10] covoar.cc: Convert to C++



On 9/9/21 2:44 am, Ryan Long wrote:
> Got rid of C-strings, changed FILE pointer to ifstream.
> ---
>  tester/covoar/covoar.cc | 52 
> +++--
>  1 file changed, 24 insertions(+), 28 deletions(-)
> 
> diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc index 
> f9d4814..746add1 100644
> --- a/tester/covoar/covoar.cc
> +++ b/tester/covoar/covoar.cc
> @@ -45,11 +45,11 @@ typedef std::list CoverageNames;  
> typedef std::list Executables;  typedef 
> std::string option_error;
>  
> -bool FileIsReadable( const char *f1 )
> +bool FileIsReadable( const std::string& f1 )
>  {
>struct STAT buf1;
>  
> -  if (STAT( f1,  ) == -1)
> +  if (STAT( f1.c_str(),  ) == -1)
>  return false;
>  
>if (buf1.st_size == 0)
> @@ -177,17 +177,14 @@ int covoar(
>std::string   coverageExtension = "cov";
>Coverage::CoverageFormats_t   coverageFormat = 
> Coverage::COVERAGE_FORMAT_QEMU;
>Coverage::CoverageReaderBase* coverageReader = NULL;
> -  char* executable = NULL;
> -  const char*   explanations = NULL;
> -  const char*   gcnosFileName = NULL;
> -  char  gcnoFileName[FILE_NAME_LENGTH];
> -  char  gcdaFileName[FILE_NAME_LENGTH];
> -  char  gcovBashCommand[256];
> +  std::string   explanations;
> +  std::string   gcnosFileName;
> +  std::string   gcnoFileName;
>std::string   target;
> -  const char*   format = "QEMU";
> -  FILE* gcnosFile = NULL;
> +  std::string   format = "QEMU";
> +  std::ifstream gcnosFile;
>Gcov::GcovData*   gcovFile;
> -  const char*   singleExecutable = NULL;
> +  std::string   singleExecutable;
>rld::process::tempfileobjdumpFile( ".dmp" );
>rld::process::tempfileerr( ".err" );
>rld::process::tempfilesyms( ".syms" );
> @@ -203,7 +200,6 @@ int covoar(
>std::string   outputDirectory = ".";
>Coverage::DesiredSymbols  symbolsToAnalyze;
>bool  branchInfoAvailable = false;
> -  //Target::TargetBase*   targetInfo;
>  
>//
>// Process command line options.
> @@ -243,7 +239,7 @@ int covoar(
>/*
> * Has path to explanations.txt been specified.
> */
> -  if ( !explanations )
> +  if ( explanations.empty() )
>  throw option_error( "explanations -E" );
>  
>/*
> @@ -272,7 +268,7 @@ int covoar(
>}
>  
>if (verbose) {
> -if (singleExecutable) {
> +if (!singleExecutable.empty()) {
>std::cerr << "Processing a single executable and multiple coverage 
> files"
>  << std::endl;
>  } else {
> @@ -287,7 +283,7 @@ int covoar(
>  for (const auto& cname : coverageFileNames) {
>std::cerr << "Coverage file " << cname
>  << " for executable: " << (*eitr)->getFileName() << 
> std::endl;
> -  if (!singleExecutable)
> +  if (singleExecutable.empty())
>  eitr++;
>  }
>}
> @@ -309,7 +305,7 @@ int covoar(
>  
>// If a single executable was specified, process the remaining
>// arguments as coverage file names.
> -  if (singleExecutable) {
> +  if (!singleExecutable.empty()) {
>  
>  // Ensure that the executable is readable.
>  if (!FileIsReadable( singleExecutable )) { @@ -332,14 +328,14 @@ 
> int covoar(
>if (!coverageFileNames.empty()) {
>  if ( !dynamicLibrary.empty() ) {
>executableInfo = new Coverage::ExecutableInfo(
> -singleExecutable,
> +singleExecutable.c_str(),
>  dynamicLibrary,
>  verbose,
>  symbolsToAnalyze
>);
> 

Re: [PATCH rtems-tools v1 02/10] covoar.cc: Convert to C++

2021-09-08 Thread Chris Johns



On 9/9/21 2:44 am, Ryan Long wrote:
> Got rid of C-strings, changed FILE pointer to ifstream.
> ---
>  tester/covoar/covoar.cc | 52 
> +++--
>  1 file changed, 24 insertions(+), 28 deletions(-)
> 
> diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc
> index f9d4814..746add1 100644
> --- a/tester/covoar/covoar.cc
> +++ b/tester/covoar/covoar.cc
> @@ -45,11 +45,11 @@ typedef std::list CoverageNames;
>  typedef std::list Executables;
>  typedef std::string option_error;
>  
> -bool FileIsReadable( const char *f1 )
> +bool FileIsReadable( const std::string& f1 )
>  {
>struct STAT buf1;
>  
> -  if (STAT( f1,  ) == -1)
> +  if (STAT( f1.c_str(),  ) == -1)
>  return false;
>  
>if (buf1.st_size == 0)
> @@ -177,17 +177,14 @@ int covoar(
>std::string   coverageExtension = "cov";
>Coverage::CoverageFormats_t   coverageFormat = 
> Coverage::COVERAGE_FORMAT_QEMU;
>Coverage::CoverageReaderBase* coverageReader = NULL;
> -  char* executable = NULL;
> -  const char*   explanations = NULL;
> -  const char*   gcnosFileName = NULL;
> -  char  gcnoFileName[FILE_NAME_LENGTH];
> -  char  gcdaFileName[FILE_NAME_LENGTH];
> -  char  gcovBashCommand[256];
> +  std::string   explanations;
> +  std::string   gcnosFileName;
> +  std::string   gcnoFileName;
>std::string   target;
> -  const char*   format = "QEMU";
> -  FILE* gcnosFile = NULL;
> +  std::string   format = "QEMU";
> +  std::ifstream gcnosFile;
>Gcov::GcovData*   gcovFile;
> -  const char*   singleExecutable = NULL;
> +  std::string   singleExecutable;
>rld::process::tempfileobjdumpFile( ".dmp" );
>rld::process::tempfileerr( ".err" );
>rld::process::tempfilesyms( ".syms" );
> @@ -203,7 +200,6 @@ int covoar(
>std::string   outputDirectory = ".";
>Coverage::DesiredSymbols  symbolsToAnalyze;
>bool  branchInfoAvailable = false;
> -  //Target::TargetBase*   targetInfo;
>  
>//
>// Process command line options.
> @@ -243,7 +239,7 @@ int covoar(
>/*
> * Has path to explanations.txt been specified.
> */
> -  if ( !explanations )
> +  if ( explanations.empty() )
>  throw option_error( "explanations -E" );
>  
>/*
> @@ -272,7 +268,7 @@ int covoar(
>}
>  
>if (verbose) {
> -if (singleExecutable) {
> +if (!singleExecutable.empty()) {
>std::cerr << "Processing a single executable and multiple coverage 
> files"
>  << std::endl;
>  } else {
> @@ -287,7 +283,7 @@ int covoar(
>  for (const auto& cname : coverageFileNames) {
>std::cerr << "Coverage file " << cname
>  << " for executable: " << (*eitr)->getFileName() << 
> std::endl;
> -  if (!singleExecutable)
> +  if (singleExecutable.empty())
>  eitr++;
>  }
>}
> @@ -309,7 +305,7 @@ int covoar(
>  
>// If a single executable was specified, process the remaining
>// arguments as coverage file names.
> -  if (singleExecutable) {
> +  if (!singleExecutable.empty()) {
>  
>  // Ensure that the executable is readable.
>  if (!FileIsReadable( singleExecutable )) {
> @@ -332,14 +328,14 @@ int covoar(
>if (!coverageFileNames.empty()) {
>  if ( !dynamicLibrary.empty() ) {
>executableInfo = new Coverage::ExecutableInfo(
> -singleExecutable,
> +singleExecutable.c_str(),
>  dynamicLibrary,
>  verbose,
>  symbolsToAnalyze
>);
>  } else {
>executableInfo = new Coverage::ExecutableInfo(
> -singleExecutable,
> +singleExecutable.c_str(),

Can ExecutableInfo take std::string& ?

>  "",
>  verbose,
>  symbolsToAnalyze
> @@ -393,11 +389,11 @@ int covoar(
><< " symbols" << std::endl;
>  
>// Create explanations.
> -  if ( explanations )
> -allExplanations.load( explanations );
> +  if ( !explanations.empty() )
> +allExplanations.load( explanations.c_str() );
>  
>// Create coverage map reader.
> -  coverageFormat = Coverage::CoverageFormatToEnum(format);
> +  coverageFormat = Coverage::CoverageFormatToEnum(format.c_str());

And here.

Chris

>coverageReader = Coverage::CreateCoverageReader(coverageFormat);
>if (!coverageReader)
>  throw rld::error( "Unable to create coverage file reader", "covoar" );
> @@ -441,7 +437,7 @@ int covoar(
>  // DEBUG Print ExecutableInfo content
>  //exe->dumpExecutableInfo();
>  
> -if (!singleExecutable) {
> +if (singleExecutable.empty()) {
>   

[PATCH rtems-tools v1 02/10] covoar.cc: Convert to C++

2021-09-08 Thread Ryan Long
Got rid of C-strings, changed FILE pointer to ifstream.
---
 tester/covoar/covoar.cc | 52 +++--
 1 file changed, 24 insertions(+), 28 deletions(-)

diff --git a/tester/covoar/covoar.cc b/tester/covoar/covoar.cc
index f9d4814..746add1 100644
--- a/tester/covoar/covoar.cc
+++ b/tester/covoar/covoar.cc
@@ -45,11 +45,11 @@ typedef std::list CoverageNames;
 typedef std::list Executables;
 typedef std::string option_error;
 
-bool FileIsReadable( const char *f1 )
+bool FileIsReadable( const std::string& f1 )
 {
   struct STAT buf1;
 
-  if (STAT( f1,  ) == -1)
+  if (STAT( f1.c_str(),  ) == -1)
 return false;
 
   if (buf1.st_size == 0)
@@ -177,17 +177,14 @@ int covoar(
   std::string   coverageExtension = "cov";
   Coverage::CoverageFormats_t   coverageFormat = 
Coverage::COVERAGE_FORMAT_QEMU;
   Coverage::CoverageReaderBase* coverageReader = NULL;
-  char* executable = NULL;
-  const char*   explanations = NULL;
-  const char*   gcnosFileName = NULL;
-  char  gcnoFileName[FILE_NAME_LENGTH];
-  char  gcdaFileName[FILE_NAME_LENGTH];
-  char  gcovBashCommand[256];
+  std::string   explanations;
+  std::string   gcnosFileName;
+  std::string   gcnoFileName;
   std::string   target;
-  const char*   format = "QEMU";
-  FILE* gcnosFile = NULL;
+  std::string   format = "QEMU";
+  std::ifstream gcnosFile;
   Gcov::GcovData*   gcovFile;
-  const char*   singleExecutable = NULL;
+  std::string   singleExecutable;
   rld::process::tempfileobjdumpFile( ".dmp" );
   rld::process::tempfileerr( ".err" );
   rld::process::tempfilesyms( ".syms" );
@@ -203,7 +200,6 @@ int covoar(
   std::string   outputDirectory = ".";
   Coverage::DesiredSymbols  symbolsToAnalyze;
   bool  branchInfoAvailable = false;
-  //Target::TargetBase*   targetInfo;
 
   //
   // Process command line options.
@@ -243,7 +239,7 @@ int covoar(
   /*
* Has path to explanations.txt been specified.
*/
-  if ( !explanations )
+  if ( explanations.empty() )
 throw option_error( "explanations -E" );
 
   /*
@@ -272,7 +268,7 @@ int covoar(
   }
 
   if (verbose) {
-if (singleExecutable) {
+if (!singleExecutable.empty()) {
   std::cerr << "Processing a single executable and multiple coverage files"
 << std::endl;
 } else {
@@ -287,7 +283,7 @@ int covoar(
 for (const auto& cname : coverageFileNames) {
   std::cerr << "Coverage file " << cname
 << " for executable: " << (*eitr)->getFileName() << std::endl;
-  if (!singleExecutable)
+  if (singleExecutable.empty())
 eitr++;
 }
   }
@@ -309,7 +305,7 @@ int covoar(
 
   // If a single executable was specified, process the remaining
   // arguments as coverage file names.
-  if (singleExecutable) {
+  if (!singleExecutable.empty()) {
 
 // Ensure that the executable is readable.
 if (!FileIsReadable( singleExecutable )) {
@@ -332,14 +328,14 @@ int covoar(
   if (!coverageFileNames.empty()) {
 if ( !dynamicLibrary.empty() ) {
   executableInfo = new Coverage::ExecutableInfo(
-singleExecutable,
+singleExecutable.c_str(),
 dynamicLibrary,
 verbose,
 symbolsToAnalyze
   );
 } else {
   executableInfo = new Coverage::ExecutableInfo(
-singleExecutable,
+singleExecutable.c_str(),
 "",
 verbose,
 symbolsToAnalyze
@@ -393,11 +389,11 @@ int covoar(
   << " symbols" << std::endl;
 
   // Create explanations.
-  if ( explanations )
-allExplanations.load( explanations );
+  if ( !explanations.empty() )
+allExplanations.load( explanations.c_str() );
 
   // Create coverage map reader.
-  coverageFormat = Coverage::CoverageFormatToEnum(format);
+  coverageFormat = Coverage::CoverageFormatToEnum(format.c_str());
   coverageReader = Coverage::CreateCoverageReader(coverageFormat);
   if (!coverageReader)
 throw rld::error( "Unable to create coverage file reader", "covoar" );
@@ -441,7 +437,7 @@ int covoar(
 // DEBUG Print ExecutableInfo content
 //exe->dumpExecutableInfo();
 
-if (!singleExecutable) {
+if (singleExecutable.empty()) {
   eitr++;
 }
   }
@@ -455,18 +451,18 @@ int covoar(
   //
   // Generate Gcov reports
   //
-  if (gcnosFileName) {
+  if (!gcnosFileName.empty()) {
 if (verbose)
   std::cerr << "Generating Gcov reports..." << std::endl;
 
-gcnosFile = fopen ( gcnosFileName , "r" );
+gcnosFile.open( gcnosFileName );
 
 if ( !gcnosFile )
   std::cerr <<