Is there a point to trapping “segfault”?

后端 未结 6 1728
时光说笑
时光说笑 2021-01-03 04:03

I know that, given enough context, one could hope to use constructively (i.e. recover) from a segfault condition.

But, is the effort worth it? If yes, in w

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-03 04:34

    A number of the reasons:

    1. To provide more application specific information to debug a crash. For instance, I crashed at stage 3 processing file 'x'.
    2. To probe whether certain memory regions are accessible. This was mostly to satisfy an API for an embedded system. We would try to write to the memory region and catch the segfault that told us that the memory was read-only.
    3. The segfault usually originates with a signal from the MMU, which is used by the operating system to swap in pages of memory if necessary. If the OS doesn't have that page of memory, it then forwards the signal onto the application.

提交回复
热议问题