[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with printk() function



I'm having a couple of problems with the printk() function.

a)  The optional precision value doesn't seem to be supported for
    hexadecimal values (types x and X).  Then again, I haven't played with
    it enough yet to see if precision is supported at all...

b)  If the format string does not end with a newline character, no output is
    displayed.

The following are some code snippets and output displays of what I've been
running into.

Initial code (1), output display (2) and comments (3 and 4).
Modified code with more tests (5), output display (6) and comments (7).

Are these bugs or features?


1) Code from network.c
----------------------

... deleted code ...

/* If we are running interrupt driven I/O no debug output is printed */
#if CD2401_IO_MODE == 0
   #define printk(arglist) do { printk arglist; printk("\r"); } while (0);
#else
   #define printk(arglist)
#endif

... deleted code ...

/*
 *  print_hdr
 *
 *  Print the contents of an ethernet packet header
 *  CANNOT BE CALLED FROM ISR
 */
static  void print_hdr(
  unsigned char *add
)
{
  int i;

  printk (("print_hdr: begins\n"))
  printk (("Header Location %p\n", add))
  printk (("Dest  "))

  for (i = 0; i < 6; i++) {
    printk ((" %2.2X", add[i]))
        }
  printk (("\nSource"))

  for (i = 6; i < 12; i++) {
    printk ((" %2.2X", add[i]))
        }
  printk (("\nframe type %2.2X%2.2X\n", add[12], add[13]))
  printk (("print_hdr: completed"))
}

... deleted code ...


2) Generated output
-------------------
print_hdr: begins
Header Location 1173D4
 .2X
 .2Xce
frame type .2X.2X


3) Disclaimer
-------------
I don't know if this was called from within an ISR or from normal execution.


4) Comments
-----------
o  printk does not seem to display data if the format string does not end
   with a newline

o  printk formatting for hex data does not seem to be working


5) Test code from rewritten network.c
-------------------------------------

... deleted code ...

/* If we are running interrupt driven I/O no debug output is printed */
#if CD2401_IO_MODE == 0
   #define PRINTK(...)  printk(__VA_ARGS__)
#else
   #define PRINTK(...)
#endif


... deleted code ...

static  void print_hdr(
  unsigned char *add
)
{
  char  buf[60];


  PRINTK("print_hdr: begins\n");
  PRINTK("Header Location %p\n", add);

  PRINTK("Dest   %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
          add[0], add[1], add[2], add[3], add[4], add[5]);
  printk("Dest   %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
          add[0], add[1], add[2], add[3], add[4], add[5]);
  printk("Dest   %2X:%2X:%2X:%2X:%2X:%2X\n",
          add[0], add[1], add[2], add[3], add[4], add[5]);
  printk("Dest   %X:%X:%X:%X:%X:%X\n",
          add[0], add[1], add[2], add[3], add[4], add[5]);
  sprintf(buf, "Dest   %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
                add[0], add[1], add[2], add[3], add[4], add[5]);
  PRINTK("%s", buf);
  printf(buf, "Dest   %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
                add[0], add[1], add[2], add[3], add[4], add[5]);


  PRINTK("Source %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
          add[6], add[7], add[8], add[9], add[10], add[11]);
  printk("Source %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
          add[6], add[7], add[8], add[9], add[10], add[11]);
  printk("Source %2X:%2X:%2X:%2X:%2X:%2X\n",
          add[6], add[7], add[8], add[9], add[10], add[11]);
  printk("Source %X:%X:%X:%X:%X:%X\n",
          add[6], add[7], add[8], add[9], add[10], add[11]);
  sprintf(buf, "Source %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
               add[6], add[7], add[8], add[9], add[10], add[11]);
  PRINTK("%s", buf);
  printf(buf, "Source %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
               add[6], add[7], add[8], add[9], add[10], add[11]);


  PRINTK("frame type %2.2x%2.2x\n", (unsigned int)add[12], (unsigned int)add[13]);
  PRINTK("print_hdr: completed\n");
}

... deleted code ...


6) Generated output
-------------------
print_hdr: begins
Header Location 116ED4
Dest   .2x:.2x:.2x:.2x:.2x:.2x
Dest   .2x:.2x:.2x:.2x:.2x:.2x
Dest   FF:FF:FF:FF:FF:FF
Dest   FF:FF:FF:FF:FF:FF
Dest   ff:ff:ff:ff:ff:ff
Dest   ff:ff:ff:ff:ff:ff
Source .2x:.2x:.2x:.2x:.2x:.2x
Source .2x:.2x:.2x:.2x:.2x:.2x
Source  8: 0:3E:27: A:AF
Source 8:0:3E:27:A:AF
Source 08:00:3e:27:0a:af
Source 08:00:3e:27:0a:af
frame type .2x.2x
print_hdr: completed


7)  Comments
------------
o  Problem does not seem to be interrupt related
o  printk does not display correct data for hex data when a precision is
   specified
o  sprintf and printf work correctly

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5218 bytes
Desc: not available
URL: <http://www.rtems.org/pipermail/rtems-users/attachments/20111219/a59c8142/attachment.bin>