开发者

Segmentation fault on valid memory

开发者 https://www.devze.com 2023-01-25 14:33 出处:网络
I get segmentation fault acces开发者_如何学Csing an object which looks valid and fully accessible in gdb. Isn\'t segmentation is always about inaccessible memory?

I get segmentation fault acces开发者_如何学Csing an object which looks valid and fully accessible in gdb. Isn't segmentation is always about inaccessible memory?

EDIT: more details.

The crash happend under gdb so I could examine the object's memory. It had the members set to proper values so there is no chance I was accessing read-only memory. The instruction where crashed happed is kind of Var = Obj.GetMember() where Var, GetMember and the corresponding member are short integers. Misalignment? I suppose it would cause bus error, not segmentation. I'll try to rebuild all. The problem is that this piece of code runs thousands times a second and the segmentation happens once in several days.


Try complete rebuild (make clean && make), this had helped me a couple of times when I encountered such weird errors.

Late UPD:

If this does fix the problem, it usually means that something is wrong with your makefile, usually screwed-up dependencies between .cpp and .h files, for example: a.cpp includes b.h, but b.h is not listed in a.cpp's dependencies.


You can get faults even if accessing "valid" memory under some circumstances:

  • you're attempting to modify memory but the specific mapping is readonly
  • you're attempting to execute code in a memory area that is no-execute
  • you're attempting to e.g. load/store at a misaligned address and your hardware issues alignment exceptions

Without a look at the coredump, to figure out what the faulting instruction (load/store/execute) was and what exactly the mapping permissions for the accessed memory were it's impossible to distinguish.


Basically, yes. Did you use the core dump to analyze your seg fault?


Code would very much help, but have you done a make clean? If you've increased the size of a class and your dependencies aren't right then there won't be enough space allocated for an instance and that class will then overrun and corrupt whatever it precedes in memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消