Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

PXL Creations

macrumors member
Original poster
Nov 28, 2009
50
0
I was finally able to compile libssh2 (thanks to a very helpful forrst'r), but now I keep seeing the `EXC_BAD_ACCESS` error.

This is the basic background as to how libssh2 works (at least the GUI) is this...

  1. Enter command
  2. Enter host IP
  3. Enter username/pass
  4. Press the button to send the SSH command

Now, simple commands like `echo Hello World` work fine, but the whole idea of this as a project was to be able to restart my mac remotely. Originally, using the command `shutdown -r` caused nothing to happen on the remote machine, and crashed the app. I then had the idea that I could simple open an applescript app that restarts the mac, by using the `open /path/to/restart.app` command, which works fine. The machine restarts, sweet.

EXCEPT, the app crashes with the following error:

Code:
Thread 1: EXC_BAD_ACCESS (code=1, address=_____)

I'm really new to objective-c, and I have no idea how to go about fixing this. Looking it up on google, I've found that it's caused by:

  1. Memory issue
  2. Message being sent to an object that's already been released (I'm not sure what this means...)

So, I'm guessing that once the command is sent via SSH, it disconnects and then tires to show the result but the object's already gone.

I'd post the source code for this, but it's a lot of different files, so I'll post the github link:

https://github.com/x2on/libssh2-for-iOS

I have not modified any of the code, so if anyone has the desire to replicate my problem, the code I'm using is the same as the one from there.

EDIT: From another forum, "... having said that you can see that libssh2_channel_open() is dereferencing a NULL pointer so you're likely passing one of the parameters as NULL. Stick a breakpoint on your call to libssh2_channel_open_ex() and check the parameters as they go in; alternatively add asserts before the call to ensure things are as you expect (a better longterm solution)." How do I follow these instructions?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
The issue that needs to be addressed is learning the tools.

Step 1: Use a project that works.
Seriously, learning to use breakpoints and the debugger will be much easier on a program that already works. Since the goal is learning the tools, not debugging a broken program, using a working program takes one problem out of the mix.

Step 2: Learn to use breakpoints.
Start by entering the search term breakpoint in Xcode's builtin documentation. Not the iOS reference docs, the builtin Help documentation for Xcode itself. Learning breakpoints also involves learning how to examine variables and interpret those values. And once a breakpoint is hit, stepping thru code a line at a time is an essential skill.

Step 3: Read online resources.
Example:
http://developer.apple.com/library/...ingYourCode/BuildingandExecutingYourCode.html
Found by googling xcode breakpoint site:developer.apple.com
That last site: search term limits the results to that specific site. It's basically how to get site-specific search results without going to the site and doing a search there.
 
Last edited:

Carob

macrumors newbie
Apr 19, 2012
11
0
Have you tried enabling Zombie Objects (NSZombieEnabled)? Usually this will help you identify where you're accessing memory that's been deallocated.
 

PXL Creations

macrumors member
Original poster
Nov 28, 2009
50
0
Thanks for the reply,

1.) I would work on a different project, but I'd like to learn how to debug a semi-working one first.

2.) I'll take a look at the docs and google how to use breakpoints better.

3.) Yes, I normally would search google but I find that when you don't completely understand the language, it's better to hear it from people who are working specifically on what you're working on. And yes, I've searched google like that many a times...

The issue that needs to be addressed is learning the tools.

Step 1: Use a project that works.
Seriously, learning to use breakpoints and the debugger will be much easier on a program that already works. Since the goal is learning the tools, not debugging a broken program, using a working program takes one problem out of the mix.

Step 2: Learn to use breakpoints.
Start by entering the search term breakpoint in Xcode's builtin documentation. Not the iOS reference docs, the builtin Help documentation for Xcode itself. Learning breakpoints also involves learning how to examine variables and interpret those values. And once a breakpoint is hit, stepping thru code a line at a time is an essential skill.

Step 3: Read online resources.
Example:
http://developer.apple.com/library/...ingYourCode/BuildingandExecutingYourCode.html
Found by googling xcode breakpoint site:developer.apple.com
That last site: search term limits the results to that specific site. It's basically how to get site-specific search results without going to the site and doing a search there.

What's the best way to do this? I tried going though the docs, but I couldn't find anything to guide me on how to set it up. Google's the next step I guess...


Have you tried enabling Zombie Objects (NSZombieEnabled)? Usually this will help you identify where you're accessing memory that's been deallocated.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.