Recent

Author Topic: macOS Sierra - Debugging not working  (Read 57125 times)

mbdev

  • New Member
  • *
  • Posts: 44
macOS Sierra - Debugging not working
« on: September 26, 2016, 12:56:36 pm »
Hi,

after upgrading to macOS Sierra I'm not able to debug my applications. After pressing the start button Lazarus will wait and nothing happens. But it's possible to create an executable and run it without debugger.

I attached a screenshot of the console output of Lazarus. I seems like Lazarus is waiting for GDB? Do you know how to fix this problem?

GDB Version: gdb-7.11
MacOS Version: OS X 10.12
Lazarus Version: 1.6
FreePascal Version: 3.0.0

esvignolo

  • Full Member
  • ***
  • Posts: 159
  • Using FPC in Windows, Linux, Macos
Re: macOS Sierra - Debugging not working
« Reply #1 on: September 26, 2016, 05:03:10 pm »
Hi, there are 2 methods at least:

Method a) (i use this one, and work on sierra)
1) Boot to recovery
2) In recovery Tools->Open Terminal
3) run "csrutil disable" (without quotes)
4) Restart

Method b) Codesign GDB the instructions are in the wiki page of lazarus.

mbdev

  • New Member
  • *
  • Posts: 44
Re: macOS Sierra - Debugging not working
« Reply #2 on: September 26, 2016, 06:20:59 pm »
Hm, I had created the key cert. for GDB on El Capitan and it worked well. The screenshot indicates that I tried to start Lazarus as superuser and the same problem occured.

I don't think that it has something to do with permissions. Which version of GDB are you using?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: macOS Sierra - Debugging not working
« Reply #3 on: September 26, 2016, 06:43:10 pm »
You got a debug PID, so something got started.

See if you can create a log http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session

mbdev

  • New Member
  • *
  • Posts: 44
Re: macOS Sierra - Debugging not working
« Reply #4 on: September 26, 2016, 06:59:56 pm »
I created an empty LCL applications and pressed run. After 10s of nothing I terminated the Lazarus process. Moreover I started lazarus as superuser to prevent possible permission problems.

You can find the full lazarus log file in my attachments.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: macOS Sierra - Debugging not working
« Reply #5 on: September 26, 2016, 07:15:26 pm »
The last thing that happens is that gdb tries to launch your app.
Afaik it only gets that far, if it is codesigned (but don't know for sure)

Unfortunately the last bits of the file were not flushed to disk. Not sure if,what they would have revealed.

You could try to run Lazarus from a console (with --log-enable / but without --log-file) then you get the output in the console window, and might get the last line.

Also once the IDE hangs, open another console, run a "ps ax" or equivalent, and see if gdb is still running. Also if your app is running.

--------------
Maybe this can be solved by changing some settings.

In Menu "Tools" > Options. Then page "Debugger".
There is a property grid. One entry is "InternalStartBreak".

You can try the other values. Maybe gdsbEntry or gdsbMainAddress.

---------------
If you run any antivirus make sure  that does not interfere.

---
Btw, when it hangs, did you try "reset debugger" from "run" menu?
« Last Edit: September 26, 2016, 09:11:46 pm by Martin_fr »

esvignolo

  • Full Member
  • ***
  • Posts: 159
  • Using FPC in Windows, Linux, Macos
Re: macOS Sierra - Debugging not working
« Reply #6 on: September 26, 2016, 09:09:09 pm »
I install with brew (in yosemite), after update to Sierra, I run:

brew upgrade gdb

This is my version now:
[MacBookeEsteban:POSBerry Esteban$ gdb --version
GNU gdb (GDB) 7.10.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin15.2.0".

Hm, I had created the key cert. for GDB on El Capitan and it worked well. The screenshot indicates that I tried to start Lazarus as superuser and the same problem occured.

I don't think that it has something to do with permissions. Which version of GDB are you using?

mbdev

  • New Member
  • *
  • Posts: 44
Re: macOS Sierra - Debugging not working
« Reply #7 on: September 27, 2016, 04:22:08 pm »
Hi,

I reinstalled gdb and recreated the cert. The problem isn't solved :/ Thank you for your help :) Do you have more ideas?

Quote
If you run any antivirus make sure  that does not interfere.
--> No antivirus

Quote
Maybe this can be solved by changing some settings.

In Menu "Tools" > Options. Then page "Debugger".
There is a property grid. One entry is "InternalStartBreak".

You can try the other values. Maybe gdsbEntry or gdsbMainAddress.
--> No effect :/

Quote
Btw, when it hangs, did you try "reset debugger" from "run" menu?
--> Yes :), but no effect

Quote
Also once the IDE hangs, open another console, run a "ps ax" or equivalent, and see if gdb is still running. Also if your app is running.
Output:
ps
  PID TTY           TIME CMD
  936 ttys000    0:00.03 -bash
  984 ttys000    0:07.96 ./lazarus --log-enable
  995 ttys000    0:00.46 /usr/local/bin/gdb -silent -i mi -nx
 1004 ttys001    0:00.03 -bash


Quote
Unfortunately the last bits of the file were not flushed to disk. Not sure if,what they would have revealed.

You could try to run Lazarus from a console (with --log-enable / but without --log-file) then you get the output in the console window, and might get the last line.
[...]
(gdb)
<-break-insert -f foo>
&"Function \"foo\" not defined.\n"
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="foo",times="0",original-location="foo"}
(gdb)
<-break-delete 1>
^done
(gdb)
<-break-insert main>
^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x000118a0",func="PASCALMAIN",file="project1.lpr",fullname="/Users/miguel/tmp/project1.lpr",line="20",thread-groups=["i1"],times="0",original-location="main"}
(gdb)
<-break-insert *71456>
^done,bkpt={number="3",type="breakpoint",disp="keep",enabled="y",addr="0x00011720",at="<start>",thread-groups=["i1"],times="0",original-location="*71456"}
(gdb)
<-break-insert +0>
^done,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0x00011855",func="PASCALMAIN",file="project1.lpr",fullname="/Users/miguel/tmp/project1.lpr",line="6",thread-groups=["i1"],times="0",original-location="/Users/miguel/tmp/project1.lpr:+0"}
(gdb)
<-exec-run>
=thread-group-started,id="i1",pid="997"
=thread-created,id="1",group-id="i1"
=thread-exited,id="1",group-id="i1"
=thread-group-exited,id="i1"

esvignolo

  • Full Member
  • ***
  • Posts: 159
  • Using FPC in Windows, Linux, Macos
Re: macOS Sierra - Debugging not working
« Reply #8 on: September 27, 2016, 05:16:56 pm »
Hi,

Method a) (i use this one, and work on sierra)
1) Boot to recovery
2) In recovery Tools->Open Terminal
3) run "csrutil disable" (without quotes)
4) Restart

I can debug on Sierra.



Hi,

I reinstalled gdb and recreated the cert. The problem isn't solved :/ Thank you for your help :) Do you have more ideas?

Quote
If you run any antivirus make sure  that does not interfere.
--> No antivirus

Quote
Maybe this can be solved by changing some settings.

In Menu "Tools" > Options. Then page "Debugger".
There is a property grid. One entry is "InternalStartBreak".

You can try the other values. Maybe gdsbEntry or gdsbMainAddress.
--> No effect :/

Quote
Btw, when it hangs, did you try "reset debugger" from "run" menu?
--> Yes :), but no effect

Quote
Also once the IDE hangs, open another console, run a "ps ax" or equivalent, and see if gdb is still running. Also if your app is running.
Output:
ps
  PID TTY           TIME CMD
  936 ttys000    0:00.03 -bash
  984 ttys000    0:07.96 ./lazarus --log-enable
  995 ttys000    0:00.46 /usr/local/bin/gdb -silent -i mi -nx
 1004 ttys001    0:00.03 -bash


Quote
Unfortunately the last bits of the file were not flushed to disk. Not sure if,what they would have revealed.

You could try to run Lazarus from a console (with --log-enable / but without --log-file) then you get the output in the console window, and might get the last line.
[...]
(gdb)
<-break-insert -f foo>
&"Function \"foo\" not defined.\n"
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pending="foo",times="0",original-location="foo"}
(gdb)
<-break-delete 1>
^done
(gdb)
<-break-insert main>
^done,bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x000118a0",func="PASCALMAIN",file="project1.lpr",fullname="/Users/miguel/tmp/project1.lpr",line="20",thread-groups=["i1"],times="0",original-location="main"}
(gdb)
<-break-insert *71456>
^done,bkpt={number="3",type="breakpoint",disp="keep",enabled="y",addr="0x00011720",at="<start>",thread-groups=["i1"],times="0",original-location="*71456"}
(gdb)
<-break-insert +0>
^done,bkpt={number="4",type="breakpoint",disp="keep",enabled="y",addr="0x00011855",func="PASCALMAIN",file="project1.lpr",fullname="/Users/miguel/tmp/project1.lpr",line="6",thread-groups=["i1"],times="0",original-location="/Users/miguel/tmp/project1.lpr:+0"}
(gdb)
<-exec-run>
=thread-group-started,id="i1",pid="997"
=thread-created,id="1",group-id="i1"
=thread-exited,id="1",group-id="i1"
=thread-group-exited,id="i1"

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: macOS Sierra - Debugging not working
« Reply #9 on: September 27, 2016, 06:45:55 pm »
Quote
Code: Pascal  [Select][+][-]
  1. =thread-exited,id="1",group-id="i1"
  2. =thread-group-exited,id="i1"

I don't have a mac myself. But those 2 lines probably shouldn't be there.
If I interpret them correctly your app exits (at least under gdb), before it even starts. (And its not in your code, since it never reaches the first line of your code. / it may be that no code at all is run)
I have no idea why.

2 more things you can try:

1) Ensure there is a console
open a 2nd terminal (shell), that you do not use. run the command "pty", it should print something like /dev/.....
Copy this to "ConsoleTty" in the options property grid.

Or see http://wiki.lazarus.freepascal.org/Debugger_Console_App#Redirect_input_and_output_to_a_pty_.28terminal.29


2) Ensure all debug info is dwarf (but NOT dwarf 3)
In project options debug is a setting for debug info type (dwarf or stabs)
Set it to dwarf (gdb seems to be getting more issues with stabs)

Unfortunately that has to be repeated for each package too.

Or go to "additions and overrides" and add a line for ALL "*", set to -gw

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: macOS Sierra - Debugging not working
« Reply #10 on: September 28, 2016, 12:14:50 pm »
Hi, there are 2 methods at least:

Method a) (i use this one, and work on sierra)
1) Boot to recovery
2) In recovery Tools->Open Terminal
3) run "csrutil disable" (without quotes)
4) Restart

I don't understand how this by itself can change anything. Afaik, "csrutil disable" only disables SIP (system integrity protection). That functionality prevents programs from writing to certain system directories, even when they are executed as root. I have not seen any documentation anywhere that indicates it also affects the ability to debug other programs. In fact, e.g. OS X 10.10 (Yosemite) does not have SIP, but you cannot debug there either unless you codesign GDB.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: macOS Sierra - Debugging not working
« Reply #11 on: September 28, 2016, 12:39:33 pm »
I don't understand how this by itself can change anything. Afaik, "csrutil disable" only disables SIP (system integrity protection). That functionality prevents programs from writing to certain system directories, even when they are executed as root. I have not seen any documentation anywhere that indicates it also affects the ability to debug other programs.
Ah, it's here: https://developer.apple.com/library/content/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html

I haven't tried debugging on macOS 10.12 yet, I'll try it one of the coming days.

nsl

  • New Member
  • *
  • Posts: 16
Re: macOS Sierra - Debugging not working
« Reply #12 on: October 03, 2016, 01:55:21 pm »
Hi mbdev,

I have the same problem in not being able to debug - in my case with OS-X El Capitan. I followed instructions in the Wiki to install GDB using Homebrew. This installs the latest version of GDB - 7.11.

The Windows version of FPC 3.00 uses version 7.7 of GDB and I notice from the commits in the FPC trunk that there are changes being made to support GDB 7.10.

Could it be that GDB 7.11 is just not compatible with FPC 3.00? Is there any way of installing an older version of GDB for OS-X? 


 
Lazarus 2.1 on Windows 10 / macOS Mojave

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: macOS Sierra - Debugging not working
« Reply #13 on: October 03, 2016, 01:57:30 pm »
Could it be that GDB 7.11 is just not compatible with FPC 3.00?
No, it is a compatibility issue between gdb (any version) and macOS 10.12/Sierra. I haven't found a workaround yet (other than disabling SIP using csrutil, but that a bad hack).

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: macOS Sierra - Debugging not working
« Reply #14 on: October 03, 2016, 02:20:48 pm »
I heared that this:
    Boot to recovery
    Open Terminal
    type csrutil disable
is enough after reboot but I have to try it myself yet.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018