Jump to content

DSDT Debugging/Tracing to system.log

DSDT ACPI debug trace

  • Please log in to reply
10 replies to this topic

#1
RehabMan

RehabMan

    InsanelyMac Legend

  • Coders
  • 1,289 posts
  • Gender:Male
  • Location:Bellingham, WA
  • Interests:skiing, software, classic cars
Have you ever wanted to know if a certain DSDT method was being called?  Or wanted to know more about the execution path (eg. know whether the If or Else part is being executed)?  Have you wanted to print the values out of various variables, buffers and packages within your DSDT as methods are called?  
 
So have I...
 
Trying to solve DSDT issues without knowing what code is executing, what the various variables are (whether normal Name objects, EC regions or SystemMemory regions), is very challenging.  I have used some techiques in the past that were not very convenient, such as modifying ACPISensors.kext and HwMonitor so I could see select values in HwMonitor, but these were only good for one off snapshots and very cumbersome to use.
 
To make it easier, I have created ACPIDebug.kext.  With this kext and a DSDT patch, you can cause print information to system.log for DSDT debugging.  
 
It is available here: https://github.com/R...OS-X-ACPI-Debug
 
This is from the README:
 

Advanced Configuration and Power Interface (ACPI) based kernel extension for debugging DSDT code.  This kext allows one to easily trace variables and execution path from DSDT (or SSDT) code.
 
Installation:
 
To use it you must install the two components that make up the software.  First of all, you must patch your DSDT to add the RMDT (RehabMan Debug Trace) device.  The presence of this device allows the kext to load.  Apply the debug.txt patch via MaciASL.  You can also add this repo as a MaciASL "source" in MaciASL preferences: http://raw.github.co...PI-Debug/master.
 
Second, you must build and install the kext (ACPIDebug.kext).  You can build it at the command line with 'make' and install it with Kext Wizard (or your favorite kext installer), or you can install it at the command line with 'make install'.  Of course, you can also build it with Xcode.  I'm using Xcode 5.0 at the moment.
 
Third, add code to your DSDT to where you wish to cause trace messages to system.log (call \RMDT.PUSH).
 
 
Using the tracing facility:
 
The DSDT patch adds the RMDT device at the root of your DSDT.  There are several methods you can use from within the DSDT to "push" debug output to the kext:
 
PUSH: Takes a single parameter (of any type, including Packages and Buffers).  The contents of this parameter will be displayed by the kext to system.log.
 
P1, P2 through P7.  P1 does exactly the same as PUSH.  Each of these utility methods takes 1 to 7 parameters (according to the name of the method).  This makes it easy to provide descriptions for your data or have multiple variables displayed on one line in system.log.
 
The other methods COUN, and FTCH are part of the implementation.  These methods are called by ACPIDebug.kext to pull information.
 
 
Examples:
 
\RMDT.PUSH("Entering _WAK")
output: ACPIDebug: "Entering _WAK"
 
\RMDT.PUSH(Local0)
example output: ACPIDebug: 0x10
 
\RMDT.P2("Local0", Local0)
example output: ACPIDebug: { "Local0", 0x10, }
 
\RMDT.P4("OSFL() returns", OSFL(), "OSVR is", OSVR)
example output: ACPIDebug: { "OSFL() returns", 0xABC, "OSVR is", 0x60, }
 
Name(TEST, Buffer() { 128, 255, 10, 127 }
\RMDT.P1(TEST)
output: ACPIDebug: { 0x80, 0xFF, 0x0A, 0x7F, }
 
Name(TEST, Package() { Package() { 128, 255 }, Package() { 1, 2, 3, 10 })
output: ACPIDebug: { { 0x80, 0xFF }, { 0x1, 0x2, 0x3, 0xA }, }
 
 
How it works:
 
Internally the RMDT device maintains a ring buffer of objects added via PUSH (ring buffer uses a Package).  The ring buffer size is 256.  The ACPIDebug.kext polls the RMDT device (via FTCH) every 100ms to see if any objects are available for printing.  If they are they are pulled from the ring buffer and output to system.log (it is a FIFO ring).  Objects added to the ring buffer when it is full are ignored.


Update 2014-01-18

See this post for information on the 2014-0118 version: http://www.insanelym...g/#entry1986372

 
Note: I also posted this over at TMX, but it may well be more interesting to the more "developer oriented" community here at IM.

#2
RehabMan

RehabMan

    InsanelyMac Legend

  • Coders
  • 1,289 posts
  • Gender:Male
  • Location:Bellingham, WA
  • Interests:skiing, software, classic cars
This tool has already revealed a bug in 10.8.5+.

OS X is passing garbage in Arg0 to DSDT _WAK (called upon wake from sleep). On wake from S3 it should be 3. Many DSDTs have code which compares Arg0==3 or Arg0==4 to restore state. Having Arg0==garbage could cause strange things to happen on wake from sleep, so watch out for it.

Here are a couple of DSDT patches that can work around the issue:
into method label _WAK code_regex \s(.?WAK\s+\([^)]*\)) replace_matched
begin
If (LOr(LLess(Arg0,1),LGreater(Arg0,5))) { Store(3,Arg0) }\n
%1
end;
Or:
into method label _WAK code_regex ([\s\S]*) replace_matched
begin
If (LOr(LLess(Arg0,1),LGreater(Arg0,5))) { Store(3,Arg0) }\n
%1
end;
Which one you might use depends on the specifics of the code in your _WAK method in your DSDT.

#3
chris1111

chris1111

    InsanelyMac Legend

  • Donators
  • 1,110 posts
  • Gender:Male
  • Location:Montreal Canada

Great JOB  B)  Thanks Rehabman !



#4
pere

pere

    InsanelyMac Legend

  • Members
  • PipPipPipPipPipPipPip
  • 726 posts

Very, very interesting, thanks for your effords, will keep an eye on this thread.



#5
RehabMan

RehabMan

    InsanelyMac Legend

  • Coders
  • 1,289 posts
  • Gender:Male
  • Location:Bellingham, WA
  • Interests:skiing, software, classic cars
FYI... Recently added a new feature to this kext. It allows you to invoke ACPI calls "on demand" from Terminal using ioio.

It is described in the README:

Forcing calls into RMDT from Terminal:

With the latest changes you can also force calls into methods in RMDT by using ioio. For ioio, see: https://github.com/RehabMan/OS-X-ioio

The mapping of properties to methods is as follows:

dbg0 -> DBG0
dbg1 -> DBG1
...
dbg9 -> DBG9

The methods will take one parameter (which is the value that the property was set to). The return value of the method is ignored.

So, in the RMDT device, you can add a method as such:

Method(DBG0, 1, Serialized)
{
   \RMDT.P2("DBG0 Arg0=", Arg0)
   If (LEqual(Arg0, 5))
   {
      \RMDT.P1("You set dbg0 to 5")
   }
   Else 
   { 
      \RMDT.P1("You set dbg0 to something other than 5")
   }
}
You could, of course, output any other DSDT data you wanted to in that method.

In order to trigger the method, set the 'dbg0' property with ioio:

# in Terminal
ioio -s org_rehabman_ACPIDebug dbg0 5



#6
Kuebeker

Kuebeker

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 142 posts

If you want to use DSDT Editor.app...

Use MacASL to compile and save it as an AML

Open that AML with DSDT Editor.app and save it as .DSL

You will now be able to wor on it with DSDT Editor.app.



#7
RehabMan

RehabMan

    InsanelyMac Legend

  • Coders
  • 1,289 posts
  • Gender:Male
  • Location:Bellingham, WA
  • Interests:skiing, software, classic cars

If you want to use DSDT Editor.app...

Use MacASL to compile and save it as an AML

Open that AML with DSDT Editor.app and save it as .DSL

You will now be able to wor on it with DSDT Editor.app.

Unless there are bugs in DSDT Editor, you should be able to apply the patch with DSDT Editor as well.

 

I don't use DSDT Editor, so I have not (will not) test with DSDT Editor.  DSDT Editor being based on Java is just too buggy to use (for me), which is why I use MaciASL exclusively (it is a native app... not based on garbage like Java).



#8
Kuebeker

Kuebeker

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 142 posts

Unless there are bugs in DSDT Editor, you should be able to apply the patch with DSDT Editor as well.

 

I don't use DSDT Editor, so I have not (will not) test with DSDT Editor.  DSDT Editor being based on Java is just too buggy to use (for me), which is why I use MaciASL exclusively (it is a native app... not based on garbage like Java).

 

I don't think DSDT Editor.app have been updated in a while that is probably why it's buggy reading and or applying your patch. I've started to use MaciASL. There are some features I'd like to see but it's workable as it ls. 

 

BTW. your kext is so freaking cool!!!!!



#9
Kuebeker

Kuebeker

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 142 posts

I see some ACPIDebug log entries like the following:

2/14/2014 5:53:49.000 PM kernel[0]: ACPIDebug::message(-536707056, 0xffffff8012cc2c00, 0xffffff80f1e9be8c)

2/14/2014 5:53:49.000 PM kernel[0]: ACPIDebug::message(-536707056, 0xffffff8012cc2c00, 0xffffff80f1653e8c)
What does it mean? 


#10
RehabMan

RehabMan

    InsanelyMac Legend

  • Coders
  • 1,289 posts
  • Gender:Male
  • Location:Bellingham, WA
  • Interests:skiing, software, classic cars

 

I see some ACPIDebug log entries like the following:

2/14/2014 5:53:49.000 PM kernel[0]: ACPIDebug::message(-536707056, 0xffffff8012cc2c00, 0xffffff80f1e9be8c)

2/14/2014 5:53:49.000 PM kernel[0]: ACPIDebug::message(-536707056, 0xffffff8012cc2c00, 0xffffff80f1653e8c)
What does it mean? 

 

Look at the source, line 117 in ACPIDebug.cpp, function ACPIDebug::message.  That line should probably be changed to DEBUG_LOG.



#11
Kuebeker

Kuebeker

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 142 posts

I've just did a change request from message to Debug log through https://github.com. 

It's the first time I do something like that and I have no idea what I'm doing. Hope it worked ok.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy