Intel Pin 3.0 does not recognize MPX instructions? - intel-pin

I have the latest version of Intel Pin 3.0 version 76887.
I have an MPX-enabled toy example:
#include <stdio.h>
int g[10];
int main(int argc, char **argv) {
int x = g[11];
printf("%d\n", x);
return 0;
}
When compiled with gcc + MPX, I see MPX instructions in the disassembly via objdump, and the example correctly writes me a bounds violation:
Saw a #BR! status 0 at 0x401798
Now I'd like to count the total number of specific MPX instructions using Intel Pin, e.g., BNDLDX and BNDMK.
My first attempt was using the shipped tool source/tools/SimpleExamples/trace.cpp. This tool showed me NOPs at places of MPX instructions.
In my second attempt, I wrote my own tool with the following snippet:
xed_iclass_enum_t iclass = (xed_iclass_enum_t)INS_Opcode(ins);
if (iclass == XED_ICLASS_BNDMK)
INS_InsertPredicatedCall(ins, IPOINT_BEFORE, (AFUNPTR)countBndmk, IARG_END);
This doesn't work, countBndmk is never called. I double-checked my code with other instruction iclasses, and they worked. So clearly there is a problem of Pin (or XED?) not recognizing MPX instructions.
Browsing the docs, I noticed an interesting knob
KNOB<BOOL> knob_mpx_mode(KNOB_MODE_WRITEONCE,"supported:xed","xed_mpx_mode","0","Enable Intel(R) MPX instruction decoding")
This knob seems to enable MPX decoding and is 0 by default, and I don't know how to enable it per command-line or in my tool. I found no other references to this problem in code or internet.
I know I could use Intel SDE to dump the debug trace including MPX instructions. I wonder if there is a way to enable MPX in Intel Pin. Or the only solution is to decode opcodes myself?

Maybe a little bit late to answer, but it seems that you have just to pass the option to PIN.
A little bit of background:
On the Intel manual there's this line (nothing to do with MPX, but it gives a clue):
Add the knob support_jit_api to the Pin command line as Pin tool option:
<Pin executable> <pin options> -t <Pin tool> -support_jit_api <Other Pin tool options> -- <Test application> <Test application options>
It happens there's an existing KNOB for this option:
KNOB<BOOL> LEVEL_PINCLIENT::KnobJitApi ( KNOB_MODE_WRITEONCE ,
"pintool:sym" ,
"support_jit_api" ,
"0" ,
"Enables the Jitted Functions Support"
)
As the MPX knob is defined as:
KNOB<BOOL> knob_mpx_mode(KNOB_MODE_WRITEONCE,"supported:xed","xed_mpx_mode","0","Enable Intel(R) MPX instruction decoding")
I guess you just have to pass the option to PIN:
<Pin executable> <pin options> -t <Pin tool> -xed_mpx_mode <Other Pin tool options> -- <Test application> <Test application options>
It seems that those KNOBs are hardcoded onto PIN / PinTools.

Related

VSCode: Arduino Board Configuration offers no boards to select

After I used VSCode (current version 1.61.0) and the Arduino IDE (1.8.13 / 1.8.16 - WIndows installer version) for about a year on two Windows 10 devices both devices stopped showing available Arduino / ESP8266 board types yesterday.
The Arduino board configuration only shows one item "Selected Board:" with an empty drop down.
The Arduino IDE on both devices still works (Tools - Boards show the familiar collection of boards)
My settings (searched for Arduino) are
{
"arduino.path": "C:\\Program Files (x86)\\Arduino"
}
on both devices - I have not changed this since the setup about a year ago and the Arduino IDE is still there und my c-drive.
What else can I check or what settings might lead to an empty board selector?
Its a bug in v0.4.6 of vscode arduino extention. Roll back to v0.4.5 and before, Works fine.
Same problem here. I think its a bug in the vscode extension. My workaround is to manually set the Bord type in the .vscode/arduino.json file. Simply add the
"board": "arduino:avr:uno", line to your json and it will work.
{
"port": "COM5",
"board": "arduino:avr:uno",
"sketch": "example.ino"
}
First you need to install the board you need from:
View / Command Palette / Arduino: Board Manager
Then you can select your board from:
View / Command Palette / Arduino: Board Configuration

Qprocess and avrdude

i'm trying to create a simple QT program that allows me to launch avrdude without using command line operations.
I saw that with Qprocess it's easy to launch any kind of program and I tried succesfully with simple programs like Explorer Word and Others.
The problem is that when i try to open cmd.exe nothing happens, even if i try to pass a batch file containing all the information to launch correctly avrdude.
Here's the code
QProcess *process = new QProcess(this);
process->startDetached("cmd.exe",QStringList()<<"C:/avrdude/avr.bat");
I wrote a minimal sample application which shows how to start cmd with a command using QProcess::startDetached() (on button click):
// standard C++ header:
#include <iostream>
// Qt header:
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
#include <QProcess>
int main(int argc, char **argv)
{
// main application
#undef qApp // undef macro qApp out of the way
QApplication qApp(argc, argv);
QMainWindow qWin;
QPushButton qBtn(QString::fromLatin1("Start cmd"));
QObject::connect(&qBtn, &QPushButton::clicked,
[](bool) {
bool ret = QProcess::startDetached(
#if 1 // let Windows search for cmd.exe in %PATH%
QString::fromLatin1("cmd.exe"),
#else // define exact path of cmd.exe
QString::fromLatin1("C:\\Windows\\system32\\cmd.exe"),
#endif // 1
QStringList()
<< QString::fromLatin1("/K")
<< QString::fromLatin1("echo Hello"));
std::cout << "QProcess::startDetached():"
<< (ret ? "OK." : "Failed!") << std::endl;
});
qWin.setCentralWidget(&qBtn);
qWin.show();
return qApp.exec();
}
The Qt project file is left as exercise. (Sorry, I used CMake for this.)
Please, note the #if 1. If 1 is replaced by 0 the alternative code with full path is used. (During chat session we examined special problems with starting the cmd.exe.) On my system, both alternatives did as well.
(My system: Windows 10, VS2013, Qt 5.7)
I too have been working on a Qt program where there are a couple calls to AVRDUDE. This is what worked for me. Here's the code I made for a read of the AVR device through AVRDUDE, followed by a couple of comments.
void MainWindow::call_AVRDUDE_read() //AVR READ
{
QProcess CommandPrompt;
QStringList Arguments;
QString COMPortUsed = (ui->COM_Port_Used->text()); // get the COM port from the user off UI
Arguments << "/C avrdude -c arduino -P "+ COMPortUsed +" -b 115200 -p ATmega328P -e -U eeprom:r:fromEEPROM.bin:r";
CommandPrompt.start("cmd",Arguments);
CommandPrompt.waitForFinished();
}
Here's something else which may well influence things in your application. In my case, I am reading the AVR's EEPROM. There is another routine that writes the EEPROM, but it is essentially the same as above, but a different script is sent.
In BOTH these cases, the AVRDUDE operation takes a few seconds to perform its task. When you use the QProcess::startDetached(), it has the disadvantage that control will return IMMEDIATELY after the AVRDUDE script is called through the QProcess. This can cause problems, if for instance you wanted to (as in my case) read the contents of the EEPROM and try to do so before the read actually completes.
An alternative to startDetached() you might consider trying is shown below. This will retain control until the process is finished, which may be pretty important to you. Use these two lines to replace the startDetached() call you are currently using.
CommandPrompt.start("cmd",Arguments);
CommandPrompt.waitForFinished();
This will wait for the AVRDUDE process to finish before control is returned.
The take away here though is that QProces::startDetached() may return prematurely in your application. Just beware of that.

Running an Arduino program in NetBeans 7.3

I am using Arduino and NetBeans in my project. My final work is to switch from Arduino program to Java. I managed to install an Arduino-NetBeans plugin as described in Arduino - NetBeans Plugin detail
My Arduino program includes
Serial.begin(9600); /////// Serial.print();
I get an error saying that "Unable to resolve identifier Serial". How can I solve this?
this is what you have to add to your source file:
#include <Arduino.h>
// imports the Serial class to allow log output
extern HardwareSerial Serial;
then it will work.
As answered by cgo you can add extern HardwareSerial Serial;
Or into your Project Settings, go to BUILD > C++ COMPILER > PREPROCESSOR DEFINITIONS and add: __AVR_ATmega328P__ (if you are working with Arduino UNO)
The message "unable to resolve identifier Serial" means that the compiler is searching for the variable Serial, but cannot find its declaration. You should check if you include all header files properly. I don't know the NetBeans plugin, but I guess the Serial-structure/class is initialised there.
If that is not helping, you should check the compiler otions and set them to default, as described on the project-site.

Processing to Arduino "IllegalAccessError"

I hope this exact issue was not addressed already. I did search for a while.
So I'm using the Arduino library for Processing, testing it by simply having it blink an LED that I have connected to my Arduino UNO. I'm following this tutorial, but am having a problem a little different than the ones covered on that tutorial page. Here's my Processing code:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int ledPin = 13;
void setup()
{
//println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 57600); //error here
arduino.pinMode(ledPin, Arduino.OUTPUT);
}
void draw()
{
arduino.digitalWrite(ledPin, Arduino.HIGH);
delay(1000);
arduino.digitalWrite(ledPin, Arduino.LOW);
delay(1000);
}
Here's my error:
IllegalAccessError: tried to access class processing.core.PApplet$RegisteredMethods from class cc.arduino.Arduino$SerialProxy
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
Exception in thread "Animation Thread" java.lang.IllegalAccessError: tried to access class processing.core.PApplet$RegisteredMethods from class cc.arduino.Arduino$SerialProxy
at cc.arduino.Arduino$SerialProxy.<init>(Arduino.java:119)
at cc.arduino.Arduino.<init>(Arduino.java:168)
at sketch_130206a.setup(sketch_130206a.java:29)
at processing.core.PApplet.handleDraw(PApplet.java:2117)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
at processing.core.PApplet.run(PApplet.java:2020)
at java.lang.Thread.run(Thread.java:680)
Since my error apparently has to do with access permissions, I tried doing what it says at the tutorial page I was following by going to /var/lock folder, but the /lock folder doesn't exist! I'm using a Mac 10.8.2. I searched around and found this thread (arduino dot cc/forum/index.php?topic=135164.0) and decided to try "sudo mkdir -p /var/lock" and "sudo chmod 777 /var/lock" in terminal, but it didn't change the error I have in Processing, even after restarting it. I also tried opening the Arduino app and uploading the StandardFirmata sketch as mentioned at the ProcessngxArduino library download page (playground.arduino dot cc/interfacing/processing) while trying to run the processing sketch, but same error. The fact that I'm using the Arduino UNO instead of the Duemilanove shouldn't be the issue as the UNO is apparently just an updated version of it. Any ideas what I could try to do next?
UPDATE: Okay so the highlighted error in my code is what opens the serial port I'm using at whatever rate (57600 bits/sec in this case I think). So I think the problem lies in this particular step in the instructions at the adrunio x processing info page mentioned earlier(playground dot arduino dot cc/interfacing/processing), step 3: "Configure Processing for serial: processing dot org/reference/libraries/serial/"... the link goes to processing's 'serial' reference page. I'm confused about what is meant by "configure"? How exactly do I figure out my "correct serial port"? I went through the rest of the instructions and the examples on the serial reference page, and still have no idea what I'm looking for.
UPDATE #2: My serial port for the arduino is "/dev/tty.usbmodem1411". I am still confused about how to plug this in to my code in Processing though. The things I just learned in these last 2 updates might be irrelevant to my error, I'm still unsure.
The problem was that I was using the beta version of Processing (2.0). Use the latest stable version (1.5.1) and it should work.

How can I see qDebug messages while debugging in QtCreator

I'm making the transition from Eclipse CDT (with Qt integration plugin) to QtCreator 2.0 but there is still one thing that bother me with QtCreator :
When I debug in QtCreator, I don't see my qDebug messages inside the Application output tab until I stop the application I'm debugging... Then they are all displayed at once which is not very useful.
With Eclipse, I don't have this problem : the qDebug messages are displayed correctly when encountered while stepping through the source code.
I'm using both Eclipse CDT and Qt Creator under Windows. I didn't try under Linux (which is not an option right now).
While not a complete answer, you can install DebugView (If you're on an XP machine) to view the qDebug output while you try to figure this out.
Another solution might be considered a hack, but works quite nicely, is to simply hijack debug messages yourself:
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <iostream>
void msgHandler( QtMsgType type, const char* msg )
{
const char symbols[] = { 'I', 'E', '!', 'X' };
QString output = QString("[%1] %2").arg( symbols[type] ).arg( msg );
std::cerr << output.toStdString() << std::endl;
if( type == QtFatalMsg ) abort();
}
int main(int argc, char *argv[])
{
qInstallMsgHandler( msgHandler );
QCoreApplication a(argc, argv);
qDebug() << "Hello world.";
qWarning() << "Uh, oh...";
qCritical() << "Oh, noes!";
qFatal( "AAAAAAAAAH!" );
return a.exec();
}
Which would output:
[I] Hello world.
[E] Uh, oh...
[!] Oh, noes!
[X] AAAAAAAAAH!
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
This is actually a modification of some code that I use myself to send qDebug, qWarning, etc., to a log file.
You don't have to close the application to see qDebug() messages.
There is a tab named 3 - Application output at the very bottom of the Qt Creator. Clicking that window will show you the Application output window at the bottom of Qt Creator.
That particular window will display the qDebug() messages as soon as they get called while the application is still running.
Hope it helps.
Edit:
I am not sure whether this is an answer but it might be a good valid cause.
From qDebug() documentation,
The Qt implementation of these
functions prints the text to the
stderr output under Unix/X11 and Mac
OS X. With Windows, if it is a console
application, the text is sent to
console; otherwise, it is sent to the
debugger.
Now Qt Creator doesn't have it's own debugger attached to it.
From Qt Creator documentation, we have to manually install the debugger. Since you are using Windows, you need to install Debugging tools for Windows manually.. More documentation can be found here...
Though am not used to Eclipse CDT, I assume there might be a Debugger attached to it and hence it displays the Debugging output correctly..
Since there isn't a Debugger attached to the Qt Creator, it might be behaving strangely..
Just give it a try..
To add to the above answers..
Always make sure to build in debug mode and not in release mode..
As qDebug() , only works with the debug build.
This was the silly mistake i made, before my search for the led me here, and i wanted to add this fine but important point, to the list of other answers.
Have you tried to add the following line to your .pro?
OUTPUT += Console
Then you can output on std::cout.
Let me tell you something:
Once I have developed a c++ console application on linux. During running the application it was reading a file and starting to process some logic by printing out some status messages. When I run that application the output was OK. So for convenient debugging I have decided to run the application like this:
./a.out |& tee log
This command redirects standard output (may be also standard error I don't remember) into a file named "log". So when I run with this option I saw that it writes in the log file exactly the same as in std out only there are some displacements like this:
in std out - desired output
A
operation 1 success
B
operation 2 success
C
operation 3 success
D
operation 4 success
in the log file - output with displacement (this is not correct)
A
B
C
D
operation 1 success
operation 2 success
operation 3 success
operation 4 success
I guess your problem is this kind of one... I have taken a look at QDebug and have not seen any function that frees the buffer (something like operation called flush). So I recommend you to not waist your time on this kind of small issue (I also consider that Qt Creator 2.0 is release as a beta version and it may appear a bug) and use one of the following:
qFatal()
qCritical()
qWarning()
QMessageBox
I personally use QMessageBox::about in order to debug as you can stop the screan and read the value in a very usefull places that with debugger you can't (I mean you can but you can't see the current state of you GUI application as debugger have taken the control).
Hope helps.
This is a workaround, but you could probably install your own message handler. Take a look at qInstallMsgHandler in the documentation if you have not done so already.
I have a similar issue on Ubuntu 9.10 with Qt Creator 2.0 and Qt 4.7.0, though I don't see stdout output until the application is closed. It is as if the buffer isn't flushed.
Printing to stderr shows the output in the Application output window immediately though.
fprintf(stderr, "Test1 \n"); // Prints immediately
fprintf(stderr, "Test2 \n\r"); // Prints immediately
fprintf(stdout, "Test3 \n"); // Delayed until app termination
fprintf(stdout, "Test4 \n\r"); // Delayed until app termination
qDebug() << "Test6 \n\r"; // Does not print at all
None of these answers were right for me (Arch linux user). Rather than try to explain my troubles, here is a .pro file that worked. I'm not using the QT thread loop, purely just a simple main() that does stuff and exists. I'm using cout for my output:
QT += core
QT -= gui
CONFIG += c++14
TARGET = evo
#CONFIG += console
CONFIG -= app_bundle
#CONFIG += qt
#OUTPUT += console
TEMPLATE = app
SOURCES += main.cpp \
individual.cpp \
node.cpp \
tree.cpp
HEADERS += \
individual.h \
node.h \
tree.h
If Anyone is still looking for an answer, this is what I did:
In Debug tab go to build
under build select debug not release or profile
While running your application click the Application Output tab
Then you will see all your debugs message if you used a "qDebug()" macro.
my 2 cents contrib, in your main, just before a.exec :
qputenv("QT_ASSUME_STDERR_HAS_CONSOLE", "1");

Resources