How can you debug Safari NPAPI plugins in OSX 10.11? - debugging

Attempting to debug an NPAPI plugin by attaching to the plugin process does not appear to work in 10.11.
Attaching with lldb reveals:
sudo lldb -p 39337
(lldb) process attach --pid 39337
error: attach failed: unable to attach
This seems to affect both 'legacy' webkit used for embedded Webkit (with plugin host named WebKitPluginHost) and 'modern' webkit used in safari (with plugin host named com.apple.WebKit.Plugin.64)
I have disabled the "Debugging Restrictions" using csrutil in recovery mode, but that does not appear to help in this case.

I haven't tried it specifically in 10.11, but I find the easiest way is to add a blocking section to wait for your plugin to be debugged in the startup code:
#if WAIT_FOR_DEBUGGER
static bool beingDebugged() {
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()}; size_t mib_size = 4;
struct kinfo_proc kp; size_t kp_size = sizeof(kp);
int result = sysctl(mib, mib_size, &kp, &kp_size, NULL, 0);
return (0 == result) ? (P_TRACED & kp.kp_proc.p_flag) : false;
}
#endif
then in startup code somewhere:
#if WAIT_FOR_DEBUGGER
#warning "WILL BLOCK ON P_TRACED"
while (!beingDebugged())
sleep(1);
#endif
If you have trouble finding the right process to connect to you could have this also output the PID to a file so you can read and find it.

Related

Use shared library created with Matlab Compiler SDK in OMNeT++ simulation

I am trying to call Matlab Functions from my OMNeT simulation. Therefore I created a shared library using the mwArray API. However, when I try to run the sample code, the simulation terminates with the following error message:
Error in final launch sequence:
Failed to execute MI command:
-exec-run
Error message from debugger back end:
During startup program exited with code 0xc0000135.
Failed to execute MI command:
-exec-run
Error message from debugger back end:
During startup program exited with code 0xc0000135.
During startup program exited with code 0xc0000135.
Did anyone else encounter the same problem?
I am using OMNeT 5.6.2 and Matlab 2020a under Windows
The code for my module is
#include <omnetpp.h>
#include "compilerTest.h"
using namespace omnetpp;
class ExampleModule : public cSimpleModule
{
protected:
simtime_t timerInterval;
cMessage * timer;
protected:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
Define_Module(ExampleModule);
void ExampleModule::initialize()
{
timerInterval = 1.0;
timer = new cMessage("timer");
scheduleAt(simTime() + timerInterval, timer);
}
void ExampleModule::handleMessage(cMessage *msg)
{
if (msg->isSelfMessage()){
bool x = mclInitializeApplication(NULL, 0);
scheduleAt(simTime() + timerInterval, timer);
}
}
The message indicates that the error occurred during the startup of the process. It means that the process probably cannot load the Matlab runtime DLL. The directories where the Matlab DLLs reside must be present on the system path so the operating system can load them. On Windows it is especially hard to avoid DLL hell and fix these issues (mostly because of the lack of proper error messages). First, I would try to start the example from the MinGW env command prompt where you can control the PATH manually and try to run from the IDE only after it works in the command line.

Error message "OpenCV: not authorized to capture video (status 0)" in MacOS QT

I know there were already some similar questions and it seems the question is not arose by OpenCV but by MacOS authority rule.
I have read some solutions, like create a Info.plist into source directory. And that works! But for me now only in Debug mode in QTCreator, not in Release mode. That is, when I run the program in Debug mode, everything is just OK. But in Release mode within QTCreator, the error message shows up:
OpenCV: not authorized to capture video (status 0), requesting...
16:12:22: The program has unexpectedly finished.
Some more strange informations. The program, say Test.app which is generated by QTCreator in Release or Debug mode, can be executed by directly double clicking on it or on the executable file residing in Test.app/Contents, after authorized for sure.
Additional System Information:
macOS Catalina Version 10.15.4
Qt 5.14.2
OpenCV 4.3.0
Also the Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>NSCameraUsageDescription</key>
<string>uses camera to see vision targets</string>
</dict>
</plist>
Some codes may be helpful. FYI, the program crashes before the Camera class created.
// camera.cpp
std::shared_ptr<Camera> Camera::Ptr = nullptr;
void Camera::CreateCamera()
{
if(!Ptr)
Ptr.reset(new Camera);
}
Camera::Camera()
: _device(1)
{
}
bool Camera::GrabMerged(cv::Mat &img)
{
if(_device.isOpened())
{
cv::Mat tmp;
_device.read(tmp);
if(tmp.empty())
{
qWarning("[Camera] Grab image failed.");
return false;
}
qInfo("[Camera] merged image info: cols=%d, rows=%d, channels=%d, step0=%luļ¼Œstep1=%lu, type=%d",
tmp.cols, tmp.rows, tmp.channels(), tmp.step[0], tmp.step[1], tmp.type());
cv::cvtColor(tmp, img, cv::COLOR_RGB2BGR);
return true;
}
qCritical("[Camera] Camera is not opened.");
return false;
}
...
// camera.h
class Camera: public QObject
{
...
private:
cv::VideoCapture _device;
...
}
In case helpful for others.
Qt Creator > Projects > Run > Environment > add OPENCV_AVFOUNDATION_SKIP_AUTH 0 , then you will get the MacOS prompt "QtCreator wants to access the camera". I'm running macOS 11.4
Thanks for taking time to push a minimal project that allow to reproduce the error.
After some test, it appears that this project works fine when started from command line or by double-clicking on the app bundle icon (both in Release and Debug mode). In the later case, system ask for permission to use the camera when clinking on the open button. Once permission is granted, we need to click again on the button, this is an expected behavior with OpenCV VideoCapture on macos.
But when I start it from Qt Creator, I had this weird message :
dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /usr/local/lib/libJPEG.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
18:29:38: The program has unexpectedly finished.
This is not the same as yours but that shows that there is some difference between normal execution and execution from QtCreator.
And in my case, Qt Creator is the culprit.
And after disabling the DYLD_LIBRARY_PATH variable under the Run environment (Projects Settings -> Run -> Environment), it works fine from QtCreator. Hourah !
My settings looks like :
This is with Qt Creator 4.12 / Qt 5.14.2 / OpenCV 4.3.0

SIP off on mac os but still cant load my kext

i,m new to kext programming so my problem is:
i,m running macOS 10.11.6 i have turned SIP off but when i try to load my
kext using kextload and using the -v flag i get that my kext was successfully loaded:
*Requesting load of /private/tmp/kern.kext.
/private/tmp/kern.kext loaded successfully (or already loaded).*
and to check that my kext was loaded i have used kextstat :
152 0 0xffffff7f82db3000 0x2000 0x2000 com.SPX.kext.kern (1) 299868F4-9962-362D-AE3D-09579B6780DB <4>
but when i tail my kernel logs from: /var/log/system.log
using the command : tail -f /var/log/system.log
i see that error:
MacBook-Pro com.apple.kextd[47]: kext signature failure override
allowing invalid signature -67050 0xFFFFFFFFFFFEFA16 for kext
"/private/tmp/kern.kext"
my kext is a simple hello world kext and there's my code
#include <mach/mach_types.h>
#include <libkern/libkern.h>
kern_return_t kern_start(kmod_info_t * ki, void *d);
kern_return_t kern_stop(kmod_info_t *ki, void *d);
kern_return_t kern_start(kmod_info_t * ki, void *d)
{
printf("hello world");
return KERN_SUCCESS;
}
kern_return_t kern_stop(kmod_info_t *ki, void *d)
{
printf("bye kext");
return KERN_SUCCESS;
}
thanks in advance for any help
edit:
so after many test its look like the kext was loaded successfully but when it comes to the code sign issue i went through Xcode Build Settings and there i found code signing so in the code signing there's code signing identity so i set it to Don't code sign and i build it with using Xcode build tool xcodebuild -configuration Debug -target kern
but still no progress till now, so i hope someone help at least give a link or anything .
The output you're getting suggests that the kext is being loaded - code signing is not your problem.
I do notice however that your printf() calls contain no line termination. (\n) Not outputting whole lines will cause the messages to be buffered for longer than you'd expect, and run into other messages. With something like this, it should work, and you should see your messages in the system log:
printf("hello world\n");

Xcode lldb error in lauch program

i get smilar error when i try launch my application (c++ command line) from xcode , (the application work fine from terminal .
XCode: Could not launch "APP_X_Y" - 'A' packet returned an error: -1
i tried every mentioned solution in above question but none of them helped me.
i finally found problem is launching using LLDB so GDB works fine. but i want to debug my program using LLDB and launch with default config in xcode.
the error is in following lldb function:
Error
PlatformRemoteGDBServer::LaunchProcess (ProcessLaunchInfo &launch_info)
{
Error error;
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
m_gdb_client.SetSTDIN ("/dev/null");
m_gdb_client.SetSTDOUT ("/dev/null");
m_gdb_client.SetSTDERR ("/dev/null");
m_gdb_client.SetDisableASLR (launch_info.GetFlags().Test (eLaunchFlagDisableASLR));
const char *working_dir = launch_info.GetWorkingDirectory();
if (working_dir && working_dir[0])
{
m_gdb_client.SetWorkingDir (working_dir);
}
// Send the environment and the program + arguments after we connect
const char **argv = launch_info.GetArguments().GetConstArgumentVector();
const char **envp = launch_info.GetEnvironmentEntries().GetConstArgumentVector();
if (envp)
{
const char *env_entry;
for (int i=0; (env_entry = envp[i]); ++i)
{
if (m_gdb_client.SendEnvironmentPacket(env_entry) != 0)
break;
}
}
const uint32_t old_packet_timeout = m_gdb_client.SetPacketTimeout (5);
int arg_packet_err = m_gdb_client.SendArgumentsPacket (argv);
m_gdb_client.SetPacketTimeout (old_packet_timeout);
if (arg_packet_err == 0)
{
std::string error_str;
if (m_gdb_client.GetLaunchSuccess (error_str))
{
pid = m_gdb_client.GetCurrentProcessID ();
if (pid != LLDB_INVALID_PROCESS_ID)
launch_info.SetProcessID (pid);
}
else
{
error.SetErrorString (error_str.c_str());
}
}
else
{
**error.SetErrorStringWithFormat("**'A' packet returned an error: %i",** arg_packet_err);**
}
return error;
}
as you can see 'a' packet error is in lldb now question is how can fix this problem ? is there any solution to reinstall / reconfigure LLDB in xcode? can anyone find where is problem from lldb function.
i'm using latest Mac OS + Xcode 4.6.3 latest
please share your ideas .
This error happens when debugserver cannot launch the app you are trying to debug. debugserver launches, attaches, stops, inspects and controls the process - it is a small program with all of these responsibilities. It communicates to lldb (possibly inside Xcode) via the "gdb remote protocol", with some minor extensions.
If you've built your own lldb, chances are that debugserver is not properly code signed so it cannot launch apps.
If you've changed your /etc/hosts file, check that you have a line like 127.0.0.1 localhost in there. Some people have modified their /etc/hosts (I have no idea why) and removed this line, and this has caused problems for lldb trying to communicate with debugserver.
Otherwise, check the output in Console.app to see if there are any useful messages logged.
I was in the same situation. It happened after updating to Xcode 5 in my case.
After all it works fine now.
I followed the command line executions as per the comment from Jason Molenda.
When running "xcrun lldb ..." I got an error:
xcrun error failed to exec real xcrun. (no such file or directory)
After Googling, I figured this out:
xcode-select -print-path
/Developer
As my Xcode was not in there, I did:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
I don't know why, but it didn't work immediately in my case. After quitting Xcode, Terminal, etc., Xcode ran and debug worked as expected.

What does "unable to read unknown load command 0x26" means in Xcode 3.2 on Lion?

My project at work debugged under 10.6/Xcode 3.2.5 works fine but at home the same project run under Lion/Xcode 3.2.5 tosses dozens of these
unable to read unknown load command 0x26
messages in the debugger. Any ideas on what I can do to determine what GDB is complaining about? It still "seems" to work, but I have no idea what might be missing or wrong.
Note this is a regular OSX app, not iOS.
The message comes from bfd/mach-o.c:
switch (command->type)
{
case BFD_MACH_O_LC_SEGMENT:
if (bfd_mach_o_scan_read_segment_32 (abfd, command) != 0)
return -1;
break;
.....
default:
fprintf (stderr, "unable to read unknown load command 0x%lx\n",
(unsigned long) command->type);
break;
}
The warning says that BFD cannot recognize the Mach-O section load command it has encountered.
Looking at bfd/mach-o.h where known load commands are described, we find that commands there range from 0x1 to 0x18, yet nothing beyond.
Mac OS X (Lion) defines load constants in /usr/include/mach-o/loader.h (available if you've installed XCode), from 0x1 to 0x27. Therefore, the most logical explanation to seeing the warnings for load commands > 0x18 appears to be the lack of the said codes in BFD's own header.
Also, for follow-ups consider looking at: https://bugs.launchpad.net/tarantool/+bug/1018356

Resources