How to break on access of a specific global variable in gdb? [duplicate] - c

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Can I set a breakpoint on 'memory access' in GDB?
I want to trace how a specific variable is initialized,
can gdb do this kind of job?

The gdb command watch <expr> sets a breakpoint on write, rwatch on read, and awatch on read or write. You can use them as you would with breakpoints, with two considerations:
You can't use gdb expressions in them (like $esp+...)
You need support for them. Software support is much, much slower than hardware. To find out if your gdb can use hardware watchpoints, see the output of show can-use-hw-watchpoints.

Related

What is break point in code debugging? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I recently started learn programming with c. As I'm new to programming scenario I don't have much knowledge.
I would like to ask what does break point means in code block while code debugging? And how break point works?
Can you guys explain me how to debug with break point.
Thanks
Breakpoint is a place in your code, where you want the execution to stop to allow you to examine the program data and/or state. It is used for debugging and set/removed by the debugger software. There are two types of breakpoints.
Software breakpoint: the debugger is physically replacing the instruction at the specified address by a special breakpoint instruction (bkpt for ARM, int 3 for x86 e.t.c). When the processor is encountering this instruction, it is stopping and waiting for the debugger.
Hardware breakpoint - this one is available only in case the processor is supporting it, and usually only a limited number of these are available. This is a special hardware feature, so there is no need to replace the memory instructions, but just "tell" the processor (using JTAG or any othe debugging protocol) that we want it to stop at specific address.
Generally the hardware breakpoints are more robust and precise, as they are not modifying the program code and do not rely on the ability of the process to fetch and execute the breakpoint instruction.
A break point is a mark in your code where the debugger should stop so you can check values of variables and the general state of program's execution.
When you run your program using a debuger the code stops before runing the line that is marked with a breakpoint and it allows you to ckeck the values of variables at that moment.

Reset and Shutdown in pure DOS(not Command prompt in Windows) [duplicate]

This question already has answers here:
Shutdown the computer using assembly
(10 answers)
Closed 9 years ago.
In command prompt within Windows restart and shutdown are ok via internal command- shutdown.exe. But for pure DOS, is there any way to achieve the same goals ?
We can assume the platform is Intel chipset and I guess maybe accessing chipset registers is required...
Could anyone give some comments ? Thanks !
BITD the shortest program ever was reboot.com, a 5 byte program that was a jump to the reset vector at FFFF:0. Not sure if this meets your needs, but thought I'd mention it.

Volatile in C and Cpp under linux environment [duplicate]

This question already has answers here:
Why is volatile needed in C?
(18 answers)
Closed 9 years ago.
I am writing program for ARM with Linux environment.
its not a low level program, say app level
Can you clarify me what is the difference between,
int iData;
vs
volatile int iData;
Does it have hardware specific impact ?
volatile in C came into existence for the purpose of not caching the values of the variable automatically. It will tell the machine not to cache the value of this variable. So it will take the value of the given volatile variable from the main memory every time it encounters it. This mechanism is used because at any time the value can be modified by the OS or any interrupt. So using volatile will help us accessing the value afresh every time.
Read the Wiki and this page for more explanation

What tool do you use to metric performance? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What's your favorite profiling tool (for C++)
Instead of do it directly inside the C code, I want a some tool to do it for me. e.g, given some C code, it returns how long time it's was executed. Something like LinqPad and most client that given a SQL-query,it returns how time the query was executed in *conds.
You many try
1)GNU profiler (gprof) for function level profiling
http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html#SEC2
2)For overall time statistics you may use the command,
time
Example
3)You can also try parsing the files in /proc (/proc/[pid]/stat) for a particular process,
proc manual

What's the values of all the general-purpose registers, when a program starts running? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What is default register state when program launches (asm, linux)?
I know the %esp and %eip should set to proper values by the OS kernel, so that the program can run, but other registers including %ebp,%eax,%ebx,%ecx,%edx,%esi,%edi. Does OS kernel initialize them before a program running? What values should they have?
What's the value should %esp have when a program starts running?
If you ask about a C program - you can't know, it isn't your business.
For assembly, I also don't think they have meaningful values.
The information needed to execute main - the argument count, argument vector and environment pointer - is all on the stack.
See more info in this Linux Gazette article.

Resources