LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2022, 07:51 PM   #16
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083

Instead of guessing, you can check with objdump -S
Code:
int main()
{
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
        signal(SIGFPE, &funct);
   4:   48 8d 35 00 00 00 00    lea    0x0(%rip),%rsi        # b <main+0xb>
   b:   bf 08 00 00 00          mov    $0x8,%edi
  10:   e8 00 00 00 00          callq  15 <main+0x15>
        a = 1/0;//loads to register R2 therefore I have 1/0 in R2
  15:   b8 01 00 00 00          mov    $0x1,%eax
  1a:   b9 00 00 00 00          mov    $0x0,%ecx
  1f:   99                      cltd
  20:   f7 f9                   idiv   %ecx
  22:   89 05 00 00 00 00       mov    %eax,0x0(%rip)        # 28 <main+0x28>
        printf("ddd\n");
  28:   48 8d 3d 00 00 00 00    lea    0x0(%rip),%rdi        # 2f <main+0x2f>
  2f:   e8 00 00 00 00          callq  34 <main+0x34>
        return 0;
  34:   b8 00 00 00 00          mov    $0x0,%eax
}
  39:   5d                      pop    %rbp
  3a:   c3                      retq

000000000000003b <funct>:

void funct()
{
  3b:   55                      push   %rbp
  3c:   48 89 e5                mov    %rsp,%rbp
        printf("done\n");
  3f:   48 8d 3d 00 00 00 00    lea    0x0(%rip),%rdi        # 46 <funct+0xb>
  46:   e8 00 00 00 00          callq  4b <funct+0x10>
        a=900;//does not matter if I have a=900,I still have 1/0 in R2
  4b:   c7 05 00 00 00 00 84    movl   $0x384,0x0(%rip)        # 55 <funct+0x1a>
  52:   03 00 00
        exit(0);
  55:   bf 00 00 00 00          mov    $0x0,%edi
  5a:   e8 00 00 00 00          callq  5f <funct+0x24>
 
Old 04-13-2022, 11:41 PM   #17
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
Quote:
Originally Posted by ntubski View Post
Instead of guessing, you can check with objdump -S
That is fine, just we can't see how does it work.
the line
Code:
20:   f7 f9                   idiv   %ecx
will cause that sigfpe, and we would need to use a debugger, set a breakpoint in the signal handler and check where will it return to (if the exit statement is missing). Or we can print the stack (without debugger). Anyway, it will return to the same line and will [try to] execute it again.

I did not find relevant documents about it, so probably I'm wrong.
 
Old 04-15-2022, 01:46 PM   #18
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
You really don't have to "dumpster-dive into assembly code" to understand the essential idea. If you are handed a SIGSEGV, your process probably cannot reasonably continue. So, the signal handler orders the process to exit.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SIGSEGV handler (segmentation fauld handler) myp Programming 8 03-08-2011 02:17 PM
user-define signal handler & coredump for signal 11(SIGSEGV) Alexlun Linux - Software 2 05-24-2009 06:37 AM
How to reinstall a signal handler after exec ( Strange behaviour in signal handling ) lali.p Programming 0 09-20-2008 12:11 PM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration