LinuxQuestions.org
Visit Jeremy's Blog.
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 03-15-2010, 02:21 AM   #1
JJRockford
LQ Newbie
 
Registered: Feb 2010
Posts: 11

Rep: Reputation: 0
Problem with printing debug text


Have succesfully been using the following code to make very helpful debug printouts during the development of a project. Have been running the software on my computer.

However, when we run the software of the target hardware (based on an ARM9) and are reading the trace code from the debug port, the hex numbers takes on line each, instead of being all on the same line.

If it looks like this while running on my PC (Ubuntu 9.04):
/path:function(line#) Data sent 00 01 02 03

it will look like this on the target:
/path:function(line#)
/path: Data sent
/path: 00
/path: 01
/path: 02
/path: 03

Any ideas?

Code:
#ifdef TARGET
#define DEBUG_PRINT_HEX(buf, length, fmt, args...) {int16_t i;  \
                                                      DEBUG_PRINT(fmt, ## args); \
                                                      for (i = 0; i< length; i++){ \
                                                    	  syslog(LOG_INFO, " %X", buf[i] & 0xFF); \
                                                      } \
                                                      syslog(LOG_INFO, "\n");}
#else
#define DEBUG_PRINT_HEX(buf, length, fmt, args...) {int16_t i;  \
                                                      DEBUG_PRINT(fmt, ## args); \
                                                      for (i = 0; i< length; i++){ \
                                                         printf(" %X", buf[i] & 0xFF); \
                                                      } \
                                                      printf("\n");}
#endif

#ifdef TARGET
#define DEBUG_PRINT(fmt, args...) {syslog(LOG_INFO, "%s:%s(%d) ",__FILE__, __FUNCTION__, __LINE__); syslog(LOG_INFO, fmt, ## args);}
#else
#define DEBUG_PRINT(fmt, args...) {printf("%s:%s(%d) ",__FILE__, __FUNCTION__, __LINE__); printf(fmt, ## args);}
#endif
 
Old 04-02-2010, 06:50 AM   #2
pantalone
LQ Newbie
 
Registered: Aug 2009
Location: Pittsboro, NC, USA
Distribution: Ubuntu
Posts: 7

Rep: Reputation: 1
Each call to syslog is treated as a separate log message. In order to display the information on a single line, you need to pass it in a single call to syslog. I would suggest using sprintf() and/or the C string library to build up a single string that you can pass to syslog like this: syslog(LOG_INFO, "%s", msgString)
 
Old 04-06-2010, 01:47 AM   #3
JJRockford
LQ Newbie
 
Registered: Feb 2010
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks! Solved it by building everything I wanted to have in the debug info into one string, before calling syslog.

If anyone is intrested, here is the code:
Code:
#define DEBUG_PRINT_HEX(buf, length, fmt, args...) {int16_t i;  \
	BYTE hexString[150]; \
	BYTE hexStringTmp[4]; \
	uint8_t strLen; \
	hexString[0] = '\0'; \
	for (i = 0; i< length; i++){ \
		strLen = sprintf(hexStringTmp, "%X", (uint8_t) buf[i]); \
		hexStringTmp[strLen] = ' '; \
		hexStringTmp[strLen + 1] = '\0'; \
		strcat(hexString, hexStringTmp); \
	} \
	syslog(LOG_INFO, "%s:%s(%d) %s\n", __FILE__, __FUNCTION__, __LINE__, hexString);}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Problem in printing HTML content as plain text tucs_123 Programming 4 09-19-2009 01:07 AM
problem with C (printing out to text file) manolakis Programming 10 02-06-2007 02:22 AM
how to turn on samba debug to troubleshoot printing nytcorp Linux - Newbie 1 04-26-2006 06:02 AM
Printing to the debug window in VC++ .Net Guest1234 Programming 1 06-08-2005 12:23 AM
Printing webpages and emails problem - text doesn't fit and overwrites itself silverbirch Linux - Newbie 1 02-28-2005 07:14 AM

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

All times are GMT -5. The time now is 03:35 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