LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-24-2012, 11:57 AM   #1
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
HOWTO -- traditional "listing" from GCC compiler


I need to create a "report" showing C/C++ source code with the
error and warning messages mixed with the source code. This was a
traditional source code "listing" in the ancient days. Thankfully,
the integrated development environment (IDE) has made those listings
a relic, but I need to create several for a presentation.

In addition to code and messages interspersed, these "listing" reports offered a cross reference showing each identifier and the source line
where they were declared followed by a list of lines where they were used.

I made a pass thru the GCC man page and did not find anything obvious. Can anyone explain how I might get the message+code report? What about the cross reference report as a nice-to-have?

Thanks in advance,
~~~ 0;-Dan
A really olde timer
 
Old 02-24-2012, 03:22 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
I think you'll need to be more specific on what you're looking for.

What you describe vaguely sounds like a report generated by a source code linter. Wikipedia has a page for static code analysis tools.

Or perhaps a report generated by code coverage tools.

The difference between the two being, of course, the code coverage requires one (or more) runs of the target executable. The report then displays which lines of the source code were exercised during the run(s). The linter is a static source code analysis without the need to execute the code under analysis.

To use a linter, you just download, install, and run. The code coverage is a little more involved. The "default" coverage tool is gcov (which should be included with your distribution's gcc package). You then add "--coverage" to your compile and link commands to generate the support files. Run the binary under analysis, and then use gcov to generate reports.

If neither of those are what you're after, then it would be helpful if you could provide the name of the program you used before that generated the report. Ideally, the name of the program and a sample report it generated would help track down what you need.

Last edited by Dark_Helmet; 02-24-2012 at 03:24 PM.
 
Old 02-25-2012, 07:52 AM   #3
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771

Original Poster
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
I'm familiar with various code analysis tools, and thanks for the reminder about those.
No, in days long past, the compiler had options to emit a "report file" that included
the source code with any compile time warnings or errors interspersed with the lines of code. More specifically, when line-N had some error, the report showed the errors
immediately following line-N in the code. Some even included cute pointers "----------^" to mark where in the line the error got detected.

Back in the days of batch processing, this was the only way one used compilers and the stack of paper report, was how you worked the code to correctness. I was hoping that there was some obscure (nee, "arcane") option to 'gcc' that would create a merged output. That would save me the time of doing my own merge by hand for this presentation.

Cheers,
~~~ 0;-Dan
 
Old 02-25-2012, 11:09 AM   #4
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

I did not find any suitable gcc option in the man page. But, it is linux, we may do almost anything using standard set of utilities.

How about something like
Code:
$ cat test-error.c 
int main(int)
{
        printf("Hello World!\n");
}
$ gcc test-error.c 2>&1| sed -r '/error:|warning:/{p;s/([^:]*):([0-9]+):.*/sed -n "\2p" "\1"/e; s/^/BAD LINE: /}'
test-error.c: In function ‘main’:
test-error.c:1:1: error: parameter name omitted
BAD LINE: int main(int)
test-error.c:3:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
BAD LINE:       printf("Hello World!\n");
It is not perfect, but works (at least for this simple example) and hopefully can be tailored to your needs. AWK or perl are probably better options if one need more sophisticated error processing.

Edit: Given sed command uses GNU sed specific `e' flag to the s///.
Edit 2: Previous command fails if erroneous file is not in the current directory. The following may (and sometimes probably may not) solve this problem:
Code:
$ make 2>&1 | sed -r '/error:|warning:/{p;s/([^:]*):([0-9]+):.*/sed -n "\2p" $(find . | grep "\1")/e; s/^/BAD LINE: /}'

Last edited by firstfire; 02-25-2012 at 11:22 AM. Reason: Remove unused part of regular expression.
 
1 members found this post helpful.
Old 02-25-2012, 11:21 AM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Quote:
Originally Posted by SaintDanBert View Post
No, in days long past, the compiler had options to emit a "report file" that included the source code with any compile time warnings or errors interspersed with the lines of code.
My apologies. I've never encountered a compiler that generated that report. The closest thing I have ever come to that would be at my old job--using some commercially-provided/proprietary "compiler"/utility. I put compiler in quotes because my old job was authoring hardware description in Verilog. So, it was not a compiler in the typical software sense.

The only thing else I could suggest is the route firstfire suggested. Though, I'm not trying to be a bandwagon helper
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Traditional" PM that doesn't use email? SigTerm LQ Suggestions & Feedback 2 03-01-2011 02:28 PM
K3b: - Howto re-dock "Directories" and "Contents" windows back into the main window? hagies Linux - Software 4 04-26-2006 08:38 AM
How to install GCC? error "no acceptable compiler found" rohan208 Red Hat 3 04-19-2006 05:53 AM
GCC/glibc odyssee: Or "how do I upgrade my compiler environment?" BedriddenTech Slackware 5 09-01-2003 09:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration