realbasic-nug
[Top] [All Lists]

Re: Troubles with debugging

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Troubles with debugging
From: Arnaud Nicolet <anic297@mac.com>
Date: Mon, 29 Dec 2008 17:19:44 +0100
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <20E64AA7-705C-41FD-AAC3-E8AA0D313134@great-white-software.com>
References: <9E902F19-8551-4D14-9B71-8E7D9BC35C5F@mac.com> <20E64AA7-705C-41FD-AAC3-E8AA0D313134@great-white-software.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
Le 29 déc. 08 à 16:53 (soir), Norman Palardy a écrit:

On 29-Dec-08, at 8:23 AM, Arnaud Nicolet wrote:

I am trying to debug an app (ServiceApplication) which is crashing. I have found where is the problem, but it's rather confusing: in a blank service application, the same code does not produce any crash and all works fine.

Here's what I have in the app for testing:

dim a As FolderItem

a=app.ExecutableFile.Parent.Child("Gam2") 'A random application to be launched, for my tests

dim sh As Shell
System.DebugLog "Debug2a"
sh=new Shell
sh.Execute "open "+a.ShellPath

This code should launch an application (the launch method of a folderitem is not recognized for a service application, for whatever odd reason).

Launch requires a logged in user session because of the API's it uses under the hood

Well, the application in which the crash occurs is an "agent" (i.e it is launched at the same time as an user logs in), so there's always an user logged in. But I understand a ServiceApplication isn't made to run only when an user is logged in.

I have tried alternate methods, such as the LaunchWithParametersMBS function. Either way, the real app is crashing, while the code in a new project works just fine. I'm sure the crash happens there, using system.debuglog. Now, debugging the real app is a pain. It's a startup item launched with launchd. If I want to make modifications to my code and test them, I have to restart the computer.

Use the launchctl app to install it, start it, stop it, or run it whenever you want

Interesting, thanks!

Here's the crash report, which does not seem useful to me:

1 msgs40 Agent 0x0004c720 CTCPDirectMessage.ShowMessage%%o<CTCPDirectMessage>i4 + 7821

Now, I'm puzzled... I don't know what I should do to avoid that crash.
Any idea?

What does ShowMessage do?

It's a method which does this:

-Locate an helper app
-Write to a file in the bundle of the helper app for a message
-Launch the helper app (well, would do)
-Initiate a timer to wait for a reply

(I was forced to use files as AppleEvents aren't catchable by a ServiceApplication and a socket had failed to work in my testings).

The piece of code that tries to launch the helper app is actually more complex than what I wrote:

  dim a As FolderItem
  dim f As folderItem
  dim g() As FolderItem
  dim o As Boolean

if app.IsDebug then System.DebugLog "Debug1" 'IsDebug is set at startup

  a=TargetApp 'Reference to the helper app
  if a=nil or not a.exists then
    System.DebugLog "File not found."
    Return
  end if

  if app.IsDebug then System.DebugLog "Path to launch: "+a.ShellPath

  dim smv As Integer
  call System.Gestalt("sys2", smv)
  if smv=5 then 'If on Mac OS 10.5, previous method does not work
    if app.IsDebug then System.DebugLog "Debug2a"
      o=False 'o becomes true if any of the method below is reached.

//Now, there are different methods I have tried. They are executed when a folder exists (e.g if I create a folder named "1", the first one is executed):
      f=app.ExecutableFile.Parent.Child("1")
      dim sh As Shell
      if f.Exists then
        if app.IsDebug then System.DebugLog "Debug2b"
        sh=new Shell
        sh.Execute "open "+a.ShellPath
        o=True
      end if
      f=app.ExecutableFile.Parent.Child("2")
      if f.Exists then
        if app.IsDebug then System.DebugLog "Debug2c"
        sh=new Shell
        sh.Execute "open "+a.UnixpathMBS
        o=True
      end if
      f=app.ExecutableFile.Parent.Child("3")
      if f.Exists then
        if app.IsDebug then System.DebugLog "Debug2d"
        f=a.LaunchServicesOpenMBS
        o=True
      end if

//If none of the methods above have been called, I wait for the app to be launched manually (for debugging):
      if not o then
if not WaitForTargetApp(0,0,True) then 'A method that uses the ProcessMBS class
          app. System.DebugLog "Failed to find target app."
          Return
        end if
      end if
    else '10.4
      if app.IsDebug then System.DebugLog "Debug2e"
      l=new LaunchServicesLaunchParameterMBS
      l.Application=a
      l.DontAddToRecents=True
      g.append a
      f=LaunchServicesOpenXMBS(g,l)
    end if
    if app.IsDebug then System.DebugLog "Debug3"

The results I get are always the same:
Debug1
<path to app>
Debug2a
Debug2b or Debug2c or Debug2d

and nothing after that (well, a crash).
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>