Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 19, 2012, 01:03 PM   #1
PXL Creations
macrumors member
 
Join Date: Nov 2009
EXC_BAD_ACCESS with libssh2?

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?
PXL Creations is offline   0 Reply With Quote
Old Apr 19, 2012, 02:46 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
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/i...gYourCode.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 by chown33; Apr 19, 2012 at 02:51 PM.
chown33 is offline   0 Reply With Quote
Old Apr 19, 2012, 02:53 PM   #3
Carob
macrumors newbie
 
Join Date: Apr 2012
Have you tried enabling Zombie Objects (NSZombieEnabled)? Usually this will help you identify where you're accessing memory that's been deallocated.
Carob is offline   0 Reply With Quote
Old Apr 19, 2012, 06:24 PM   #4
PXL Creations
Thread Starter
macrumors member
 
Join Date: Nov 2009
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...

Quote:
Originally Posted by chown33 View Post
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/i...gYourCode.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...


Quote:
Originally Posted by Carob View Post
Have you tried enabling Zombie Objects (NSZombieEnabled)? Usually this will help you identify where you're accessing memory that's been deallocated.
PXL Creations is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
objective-c

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: EXC_BAD_ACCESS problem larswik iPhone/iPad Programming 0 Jan 27, 2014 08:33 PM
Best easy way to debug EXC_BAD_ACCESS code 1 moonman239 iPhone/iPad Programming 25 Nov 6, 2013 11:18 PM
EXC_BAD_ACCESS - Trying to retrieve string from NSArray moonman239 iPhone/iPad Programming 12 Sep 9, 2013 07:06 AM
Please Help: EXC_BAD_ACCESS error stevegreen22 Mac Programming 4 Nov 19, 2012 06:16 PM
Getting crazy also with EXC_BAD_ACCESS jivaro Mac Programming 5 Jun 1, 2012 08:49 PM

Forum Jump

All times are GMT -5. The time now is 11:05 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC