如何在dbx中的内存位置放置断点?

时间:2021-08-31 05:12:38

A co-worker has a C program that fails in a predictable manner because of some corrupted memory. He'd like to use dbx to monitor the memory location once it's allocated in order to pinpoint the code that causes the corruption.

由于内存损坏,同事有一个C程序以可预测的方式失败。他希望在分配内存位置后使用dbx监视内存位置,以便查明导致损坏的代码。

Is this possible? If so what is the syntax to produce a breakpoint at the moment of corruption?

这可能吗?如果是这样,在腐败时刻产生断点的语法是什么?

If not, what would be a good approach to fixing this sort of issue?

如果没有,那么解决这类问题的好方法是什么?

(My usual tactic is to look at the source control to see what I've changed lately, since that is usually the cause. But the code in question sounds as if it only ever worked by luck, so that won't work. Also, I've already eliminated myself as the culprit by never having worked with the code. ;-)

(我通常的策略是查看源代码控制,看看我最近发生了什么变化,因为这通常是原因。但是有问题的代码听起来似乎只是运气,所以这不起作用。 ,我已经把自己作为罪魁祸首从未使用过代码。@-)

3 个解决方案

#1


4  

Having looked more deeply, it appears the solution on recent versions of dbx is something like:

看起来更深入,似乎最近版本的dbx的解决方案是这样的:

stop access w <address>, <size>

Since <address> and <size> can be expressions, you can write commands like:

由于

可以是表达式,因此您可以编写如下命令:

stop access w &p, sizeof(int)

This assumes p is a pointer and we want to monitor the first word it points to.

这假设p是一个指针,我们想监视它指向的第一个单词。

I've also run across a fine tutorial on tracking and stomping memory bugs. It uses gdb rather than dbx, but the principles should be the same.

我还遇到了关于跟踪和踩踏内存错误的精彩教程。它使用gdb而不是dbx,但原则应该相同。

#2


1  

On AIX, you want to use stophwp:

在AIX上,您想要使用stophwp:

(dbx) help stophwp

stophwp <address> <size>

        Stop execution when the contents of the specified
        memory region change.  This is a accomplished in
        hardware and may not be available on all models.

#3


0  

I'm no Solaris dev, but you can do this with gdb and hardware breakpoints

我不是Solaris dev,但你可以用gdb和硬件断点来做这件事

#1


4  

Having looked more deeply, it appears the solution on recent versions of dbx is something like:

看起来更深入,似乎最近版本的dbx的解决方案是这样的:

stop access w <address>, <size>

Since <address> and <size> can be expressions, you can write commands like:

由于

可以是表达式,因此您可以编写如下命令:

stop access w &p, sizeof(int)

This assumes p is a pointer and we want to monitor the first word it points to.

这假设p是一个指针,我们想监视它指向的第一个单词。

I've also run across a fine tutorial on tracking and stomping memory bugs. It uses gdb rather than dbx, but the principles should be the same.

我还遇到了关于跟踪和踩踏内存错误的精彩教程。它使用gdb而不是dbx,但原则应该相同。

#2


1  

On AIX, you want to use stophwp:

在AIX上,您想要使用stophwp:

(dbx) help stophwp

stophwp <address> <size>

        Stop execution when the contents of the specified
        memory region change.  This is a accomplished in
        hardware and may not be available on all models.

#3


0  

I'm no Solaris dev, but you can do this with gdb and hardware breakpoints

我不是Solaris dev,但你可以用gdb和硬件断点来做这件事