Questions tagged [printf-debugging]

Printf debugging is a type of debugging that requires to insert trace statements (for example printf in C) that should help a programmer to understand the program flow and reason about states and decisions.

This tag should be used for

  • questions about the use of this debugging technique;
  • questions in which the author have used this technique to understand a problem in his scenario.

Related tags:

33 questions
315
votes
11 answers

How do I dump an object's fields to the console?

When I'm running a simple Ruby script, what's the easiest way to dump an object's fields to the console? I'm looking for something similar to PHP's print_r() that will work with arrays as well.
roryf
  • 29,592
  • 16
  • 81
  • 103
63
votes
6 answers

How to "debug" Haskell with printfs?

coming from the Ocaml community, I'm trying to learn a bit of Haskell. The transition goes quite well but I'm a bit confused with debugging. I used to put (lots of) "printf" in my ocaml code, to inspect some intermediate values, or as flag to see…
Vinz
  • 5,997
  • 1
  • 31
  • 52
47
votes
6 answers

What is "p" in Ruby?

I'm sure it's a silly question to those who know, but I can't find an explanation of what it does or what it is. CSV.open('data.csv', 'r') do |row| p row end What does "p row" do?
James P. Wright
  • 8,991
  • 23
  • 79
  • 142
43
votes
19 answers

What is the proper name for doing debugging by adding 'print' statements

There are many ways of doing debugging, using a debugger is one, but the simple one for the humble, lazy, programmer is to just add a bunch of print statements to your code. i.e. def foo(x): print 'Hey wow, we got to foo!', x ... …
Jerub
  • 41,746
  • 15
  • 73
  • 90
29
votes
2 answers

Best way to emulate __typeof__ for msvc or alternative workaround?

I have some code #define DEBUG_PRINT(x,...) \ do \ {\ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wunused-value\"") \ __typeof__((0,x)) _x = x; \ _Pragma("GCC diagnostic pop") \ …
Roman A. Taycher
  • 18,619
  • 19
  • 86
  • 141
8
votes
3 answers

Type overloading macro

I have a bunch of printf debug helper macros and it would be pretty cool to have to not specify the type, is there anything you can do to allow something like macro overloading in c(can be gcc specific if its available in gcc 4.3). I thought maybe…
Roman A. Taycher
  • 18,619
  • 19
  • 86
  • 141
8
votes
11 answers

Educational example to show that sometimes printf as debugging may hide a bug

I remember when I was in some course of C programming, a teacher once suggested that I use printf to watch the execution of a program that I was trying to debug. This program had a segmentation fault with a cause that I cannot remember at the…
YuppieNetworking
  • 8,672
  • 7
  • 44
  • 65
6
votes
2 answers

Setting CFLAGS for pr_debug and printk

I am trying to understand a Linux kernel module and would like to see the output of pr_debug and printk. I am using GNU Make. I understand that to get pr_debug messages, we have to use DDEBUG. So, how do I enable printk statements ? Lets say…
db42
  • 4,474
  • 4
  • 32
  • 36
3
votes
7 answers

C Programming: seg faults, printf, and related quirks

As many young programmers do, I learned the usefulness of inserting numerous print-to-console statements of "here1," "here2," and so on at different points in code to figure out when my programs are going awry. This brute force debugging technique…
JoeCool
  • 4,392
  • 11
  • 50
  • 66
2
votes
4 answers

How to print a parenthesis in C with printf?

I am trying to print a parenthesis using: printf("\)"); However, it is giving me the following warning: warning: unknown escape sequence '\)' I can't seem to find a clear explanation anywhere on how to fix this. I realize it's just a warning, but…
user5799707
  • 43
  • 1
  • 1
  • 4
2
votes
1 answer

How to pass application printf messages to /var/log/messages

I want to pass application printf log messages to the /var/log/messages. Because kernel debug messages can be visible to /var/log/messages.But i am not getting how to pass application printf log messages to the /var/log/messages. Can anyone please…
Deepak Singh
  • 1,079
  • 2
  • 11
  • 15
1
vote
2 answers

Inject string to const char* message in custom logger printf-style function

I have a debugger class which implements a printf() c style method. It looks like this: #define NO_DEBUG 0 #define NO_PREFIX 1 #define DEBUG_INFO 2 #define DEBUG_SUCCESS 3 #define DEBUG_WARN 4 #define DEBUG_ERROR 5 #define MAX_DEBUG_LEVEL…
Dr.Random
  • 430
  • 3
  • 16
1
vote
1 answer

C struct glitch? (I am new to programing in C)

I am learning how to create struct's and I am stuck on a program I made. Everything works fine until I try to input "2". When the program prints the symbol it's supposed to be "He" but prints "HeHelium" instead. I can't figure out what's wrong and…
1
vote
3 answers

For loop with printf as arguments

I can't understand why the following code outputs 10. What I understand is that !printf("0") means !0, which is TRUE. So why doesn't the code print "Sachin" #include int main() { for (printf("1"); !printf("0"); printf("2")) …
1
vote
3 answers

Ubuntu (14 & 16) Bash errors with printf loops from input containing lowercase "n" characters

I have some bash scripts I have been running on Ubuntu 14.04 and 16.04 for well over a year now. Some recent Ubuntu update has broken bash and I cannot figure out how to sort this out.…
MitchellK
  • 2,322
  • 1
  • 16
  • 25
1
2 3