This wiki has been migrated to https://gitlab.com/wireshark/wireshark/-/wikis/home and is now deprecated. Please use that site instead.
Differences between revisions 10 and 11
Revision 10 as of 2005-08-05 14:52:35
Size: 3725
Editor: BillMeier
Comment: Fix small typos
Revision 11 as of 2005-10-28 14:38:16
Size: 4627
Editor: 195
Comment: Adding description of use of console window
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:

== Printing to a console ==

Sometimes you just want to peek at some variables to see whats going on in your code,
without the need for a heavy duty debugger session. In these cases printf can be your best friend.
To get this working (on Win32 at least) you need two things:
  * Open up the console

    Start Ethereal and go to Edit|Preferences...,

    In the dialog box go to 'Open a console window' and select 'Always (debugging)',

    Click the Save button.

  * put printf statements in your code

FI you have your eye on some condition, so you can add the following to your code:

{{{ if (condition == TRUE) {
  g_print("Kilroy was here\n");
} }}}

Notice that printf doesn't work since stdio is used for communcations with the capture engine.
g_print is used instead, it works just the same.

Don't forget to remove this later, after you've found your bug :-)
Line 11: Line 37:
{{{ if(pinfo->fd->num == 1234) {
  printf("Here is my bug\n");
{{{ if (pinfo->fd->num == 1234) {
  g_print("Here is my bug\n");
Line 15: Line 41:
and simply set a breakpoint to the printf call. and simply set a breakpoint to the g_print call.

Development Tips

Here you will find various tips useful while development and debugging.

Printing to a console

Sometimes you just want to peek at some variables to see whats going on in your code, without the need for a heavy duty debugger session. In these cases printf can be your best friend. To get this working (on Win32 at least) you need two things:

  • Open up the console
    • Start Ethereal and go to Edit|Preferences..., In the dialog box go to 'Open a console window' and select 'Always (debugging)', Click the Save button.
  • put printf statements in your code

FI you have your eye on some condition, so you can add the following to your code:

{{{ if (condition == TRUE) {

  • g_print("Kilroy was here\n");

} }}}

Notice that printf doesn't work since stdio is used for communcations with the capture engine. g_print is used instead, it works just the same.

Don't forget to remove this later, after you've found your bug :-)

Breakpoint on a specific packet number

Often you know, that you have a bug/problem in your dissector, which can be found only in a specific packet.

Let's say you know packet number 1234 has a bug, so you can add the following to your code:

{{{ if (pinfo->fd->num == 1234) {

  • g_print("Here is my bug\n");

} }}}

and simply set a breakpoint to the g_print call.

Of course you will need access to pinfo, but this should be the case in any dissector.

Don't forget to remove this later, after you've found your bug :-)

Some debuggers, such as gdb and MSVC, also let you make breakpoints conditional; you could set a breakpoint at some point in a routine, and make the condition for the breakpoint be pinfo->fd->num == 1234.

Using MSVC++ for debugging

Extracted from http://www.ethereal.com/lists/ethereal-dev/200503/msg00778.html

If you are just wanting to debug Ethereal then the Win32 binaries should already include the debug symbols by default. You can look at the file config.nmake and ensure that the debug switch is enabled...

# Linker flags
# /DEBUG generate debug info
LOCAL_LDFLAGS=/DEBUG

Once you have a valid binary with debug symbols you can easily debug Ethereal by opening up the binary from within MSVC.

So from within Visual Studio just click on the file/open menu, change the file extension type to be all files, then browse to the installed location of the Ethereal binary. Typically, c:\program files\ethereal... Once you have it open you should see ethereal.exe listed in the far left window of Visual Studio. To execute Ethereal just press the F5 key. If you want to break within some location within Ethereal then just open a source file and set a break point. The execution of Ethereal.exe will halt at the specific location. You can then step through the source code to isolate/debug you issue.

Using the MSVC6 "source browser" capability

It is sometimes quite useful to be able to use the "Tools/Source Browser" capability of MSVC6 to find the definitions and references for Ethereal functions and variables.

To build and use the required "Browse Information File" (.bsc) file:

  1. Change config.nmake to add the /Fr switch to the compiler flags (in addition to making the linker flags /DEBUG change described above).

# Compiler flags
# /W3  warning level 3 (0 less - 4 most, 1 default) 
# /Zi  create .pdb file for debugging 
# /Fr  create .sbr files used by BSCMAKE to create a "Browse Information File"  
LOCAL_CFLAGS=/Zi /W3 /Fr 
  1. Build ethereal using nmake as usual
  2. Create the .bsc file as follows:

 bscmake /o ethereal.bsc *.sbr epan\*.sbr epan\dfilter\*.sbr ^
 epan\ftypes\*.sbr epan\dissectors\*.sbr gtk2.tmp\*.sbr wiretap\*.sbr
  1. Open the Ethereal binary from within Visual Studio as described above; Select Tools/Source_Browser from the Toolbar; (If an error message appears, it may be necessary to specify the location of the .bsc file under Project/Settings). Enter a valid identifier and select OK to get a list of the source locations (file names and line numbers) of the definitions and references for the identifier.

By using the keyboard shortcuts associated with the source browser it is possible to quite easily navigate through source files. (See MSVC Help for "Browse Information Files").

For example: If the cursor is located at the beginning of an identifier, entering F12 will go immediately to the source file location of the definition of the identifier. Entering <Ctrl Num *> will then move the cursor back to the previous location.

Development/Tips (last edited 2019-02-01 14:23:13 by PeterWu)