Patchwork [V12,24/27] pm_smbus: remove #ifdef DEBUG.

login
register
mail settings
Submitter Igor V. Kovalenko
Date Jan. 7, 2010, 12:05 a.m.
Message ID <b2fa41d61001061605q3e91b929sbc706877389eece3@mail.gmail.com>
Download mbox | patch
Permalink /patch/42378/
State New
Headers show

Comments

Igor V. Kovalenko - Jan. 7, 2010, 12:05 a.m.
On Thu, Jan 7, 2010 at 2:51 AM, Isaku Yamahata <yamahata@valinux.co.jp> wrote:
> On Wed, Jan 06, 2010 at 12:42:28PM +0100, Stefan Weil wrote:
>> Isaku Yamahata schrieb:
>> > remove #ifdef DEBUG by using macro.
>> >
>> > Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
>> > Acked-by: Gerd Hoffmann <kraxel@redhat.com>
>> > ---
>> > hw/pm_smbus.c | 21 ++++++++++++---------
>> > 1 files changed, 12 insertions(+), 9 deletions(-)
>> >
>> > diff --git a/hw/pm_smbus.c b/hw/pm_smbus.c
>> > index 6ef6b9e..9929d72 100644
>> > --- a/hw/pm_smbus.c
>> > +++ b/hw/pm_smbus.c
>> > @@ -37,6 +37,15 @@
>> > #define SMBHSTDAT1 0x06
>> > #define SMBBLKDAT 0x07
>> >
>> > +//#define DEBUG
>> > +
>> > +#ifdef DEBUG
>> > +# define SMBUS_DPRINTF(format, ...) printf(format, ## __VA_ARGS__)
>>
>> Debug output should go to stderr. So this would be even better:
>>
>> +# define SMBUS_DPRINTF(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
>>
>
> Yes, in general.
> However the original code sends debug output to stdout and
> Most of debug output goes to stdout than stderr. You can easily
> see it by greping with DEBUG.
>
> So at this time, I'd like to send debug output to stdout.
> (And hopefully later create a framework and make debug output go
> to stderr consistently over sources.)

Maybe logfile redirection would do as well, with a few changes to
logfile handling.
Default may be stderr or stdout (with appropriate command line switch)

This way you can do debug output to logfile always. The following
changes sets default to stdout always and prevents errors while
reopening logfile.

Patch

diff --git a/vl.c b/vl.c
index e881e45..63c199c 100644
--- a/vl.c
+++ b/vl.c
@@ -4878,6 +4878,9 @@  int main(int argc, char **argv, char **envp)
     CPUState *env;
     int show_vnc_port = 0;

+    /* Prevent unfortunate early crash with debugging fprintf */
+    logfile=stdout;
+
     init_clocks();

     qemu_errors_to_file(stderr);
l

diff --git a/exec.c b/exec.c
index 2b068f5..752e208 100644
--- a/exec.c
+++ b/exec.c
@@ -1494,7 +1494,7 @@  void cpu_single_step(CPUState *env, int enabled)
 void cpu_set_log(int log_flags)
 {
     loglevel = log_flags;
-    if (loglevel && !logfile) {
+    if (loglevel && (!logfile || logfile == stdout)) {
         logfile = fopen(logfilename, log_append ? "a" : "w");
         if (!logfile) {
             perror(logfilename);
@@ -1521,7 +1521,7 @@  void cpu_set_log(int log_flags)
 void cpu_set_log_filename(const char *filename)
 {
     logfilename = strdup(filename);
-    if (logfile) {
+    if (logfile && logfile != stdout) {
         fclose(logfile);
         logfile = NULL;
     }