访问冲突(特定胜利) [英] access violation (win specific)

查看:73
本文介绍了访问冲突(特定胜利)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一些其他代码编写的问题,我需要修理。

这是特定于Windows的,但我在这里发布它(我只是总是

访问抱怨++)。


我有一个有参考成员的班级。我正面临的问题

经常出现在WinCE手机上。问题是

某些点引用变得无效。这个引用实际上是

指向一个单例对象,我可以找到它的内存地址。

问题是在某些时候引用对象的地址发生了变化/>
(基本上存储引用的存储单元已更改)。所以,我要
必须把断言放在所有地方检查

引用对象的地址是否正确(等于单身人士的地址)

即使代码断言然后它对我没用 - 我真的需要

陷阱实际修改这个存储单元的代码而不是代码

尝试访问修改后的引用。对象的所有值

都是正确的,除了引用本身。所以...它有点奇怪为什么

它发生了。我可以完全删除该引用并使用全局

singleton,但我仍然想知道为什么引用会改变

更改(即使我删除其他内容可能会改为

此引用)


我试图使用VirtualProtect win api在

上设置PAGE_READONLYflag这4个字节来陷阱尝试owerwrite内存,但这不是
工作,因为它改为readonly整个页面,它代码刹车

其他地方。

有没有任何其他方式我可以找出这个参考如何成为

损坏

解决方案

__ PPS__< i- *********@yandex.ruwrote in news:1187371275.053089.291820 @

22g2000hsm.googlegroups.com:


我尝试使用VirtualProtect win api将

上的PAGE_READONLYflag设置为这4个字节来陷阱尝试owerwrite memory但是这并不是
work,si它只会改为整个页面,而且它代码刹车

到处都是。



将参考文件单独放入页面中:


struct foo

{

char sentinel1 [2048];

X& x;

char sentinel2 [2048];

};


这也会抓住一个覆盖的东西地址。

将哨兵设置为已知模式并定期确保模式

未受损害。


你是什么CPU使用?它是否支持单字数据监视?您可能需要使用CPU的调试功能来捕获对该地址的访问权。


__ PPS__写道:


大家好,我有一些其他代码编写的问题,我需要修复。

这是windows具体,但我在这里发布它(简直我总是

访问抱怨++)。



对。也许那些C ++人员会学习一两件关于Windows的东西,毕竟是b $ b!我们为你的慷慨而感到荣幸。 < bows>


我有一个有引用成员的类。我正面临的问题

经常出现在WinCE手机上。问题是

某些点引用变得无效。这个引用实际上是

指向一个单例对象,我可以找到它的内存地址。

问题是在某些时候引用对象的地址发生了变化/>
[..]

有没有其他方法我可以找出这个参考如何变成

corrupted



这听起来像是程序中的内存损坏缺陷(除非它在你运行的系统中是
,我怀疑)。通常的

方法来确定它发生的时间是在你的调试器中放入一个特殊的断点,这应该允许观察数据的变化

在内存中的任意位置。如果它没有,那么你正在寻找

踩过你的程序并观察你的价值参考。


在程序开始之间的某个位置放置一个断点

和你知道它发生的点。当你的调试器点击新的断点时,看看它是否已经发生。如果没有,请将

的第二个断点放在

范围的第二部分的中间(大约)。继续。如果它确实发生了,在上半场中间再放一个断点

。重新开始。这就是我们大多数人使用subpar调试器来查找我们的程序中发生的事情。


另一种方法是找出真正的地址参考成员

并放入大量的调试打印输出以试图缩小它的价格

down,但这意味着更改你的代码会突然停止

表现出错误的行为。


祝你好运!


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问




Victor Bazarov写道:


在开始之间的某个位置放置一个断点程序

以及你知道它的发生点。当你的调试器点击新的断点时,看看它是否已经发生。如果没有,请将

的第二个断点放在

范围的第二部分的中间(大约)。



嗯,我的程序有一百万行代码,有20-50个线程

同时运行,与另外10个子进行通信

的系统可以在任意时刻(异步)发送数据。

我应该把那个断点。什么和什么的中间? :-)


Hello all, i have a problem with some code written by other that I
need to fix.
This is windows specific, but I post it here anyways (simply I always
visit complangc++).

I have a class that has a reference member. The problem I''m facing
happens frequently on WinCE mobile phone. And the problem is that at
some point the reference becomes invalid. This reference actually
points to a singleton object and I can find out it''s memory address.
The problem is that at some point address of referenced object changes
(basically memory cell that stores the reference is changed). So, I
have to put asserts all over the place to check that address of
referenced object is correct (equals to the address of the singleton)
and even if code asserts then it''s of no use to me - I really need to
trap the code that actually modifies this memory cell and not the code
that tries to access modified reference. All the values of the object
are correct, except the reference itself. So... it''s a bit weird why
it happens. I may remove that reference completely and use global
singleton, but still I really want to find out why reference gets
changed (even if I remove something else may get changed instead of
this reference)

I tried to use VirtualProtect win api to set PAGE_READONLYflag on
these 4 bytes to trap attempt to owerwrite memory but this doesn''t
work, since it changes to readonly entire page and it code brakes
everywhere else.
Is there any other way I can find out how this reference becomes
corrupted

解决方案

__PPS__ <i-*********@yandex.ruwrote in news:1187371275.053089.291820@
22g2000hsm.googlegroups.com:

I tried to use VirtualProtect win api to set PAGE_READONLYflag on
these 4 bytes to trap attempt to owerwrite memory but this doesn''t
work, since it changes to readonly entire page and it code brakes
everywhere else.

Put the reference in a page by itself:

struct foo
{
char sentinel1[2048];
X& x;
char sentinel2[2048];
};

This will also catch an overwrite that''s touching neighboring addresses.
Set the sentinels to a known pattern and periodically make sure the pattern
is unscathed.

What CPU are you using? Does it support a per-word data watch? You might be
able to use the CPU''s debugging features to trap accesses to that address.


__PPS__ wrote:

Hello all, i have a problem with some code written by other that I
need to fix.
This is windows specific, but I post it here anyways (simply I always
visit complangc++).

Right. Maybe those C++ people will learn a thing or two about Windows,
after all! We''re are honoured by your generousity. <bows>

I have a class that has a reference member. The problem I''m facing
happens frequently on WinCE mobile phone. And the problem is that at
some point the reference becomes invalid. This reference actually
points to a singleton object and I can find out it''s memory address.
The problem is that at some point address of referenced object changes
[..]
Is there any other way I can find out how this reference becomes
corrupted

It sounds like a memory corruption defect in your program (unless it
is in the system on which you''re running, which I doubt). The usual
way to find out when it happens is to put a special breakpoint in
your debugger, which should allow to watch for changes in the data
at an arbitrary location in memory. If it doesn''t, you''re in for
a long session of trying to find who is changing that memory by
stepping through your program and watching the value of the reference.

Put a breakpoint somewhere halfway between the start of the program
and the point at which you know it happens. When your debugger hits
that new breakpoint, see if it has happened. If it didn''t, put the
second breakpoint in the middle (approx) of the second part of your
range. Continue. If it has actually happen, put another breakpoint
in the middle of the first half. Restart. This is how most of us
who use subpar debuggers find where sh!t happens in our programs.

Another way is to figure out the true address of the reference member
and put a whole lot of debug printouts in an attempt to narrow it
down, but that means changing your code which can suddenly stop
exhibiting the wrong behaviour.

Good luck!

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask



Victor Bazarov wrote:

Put a breakpoint somewhere halfway between the start of the program
and the point at which you know it happens. When your debugger hits
that new breakpoint, see if it has happened. If it didn''t, put the
second breakpoint in the middle (approx) of the second part of your
range.

Hmmm, my program has a million lines of code, and have 20-50 threads
running simultaneously, communicating with 10 other sub-systems who
can send data at arbitrary moments in time (asynchronously). Where
shall I put that breakpoint. The middle of what and what? :-)


这篇关于访问冲突(特定胜利)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆