I do a lot of work on older systems using the Infineon C166 microcontroller with the Keil C166 compiler. Interrupt handlers are functions with an 'interrupt' keyword at the end. Eclipse-CDT sees this keyword and marks the whole function as having a syntax error. I know I could turn the code analysis off, but I'd rather make it smarter.
Here is what an interrupt function prototype looks like:
static void timer_callback(void) interrupt 0x17 using RB_CC23
I would like to be able to teach the code analysis that the interrupt and using directives are valid.
Any help is appreciated.
Related
I've added a C++ file to my project written in Swift. It only calculates some random numbers and also uses an vector array. It's wrapper is written in Objective-C. When I try to call functions from the cpp file the App crashes after some time. But there's a strange behavior, because it doesn't crash while executing the C++ code (it runs like I expect to), but when I load a navigation controller. This hasn't to do anything with either. The console shows this:
'pthread_mutex_lock(&mutex)' failed with error 'EINVAL'(22)
I googled this bug, but I don't really understand the problem in my case.
Because you're using threaded code - the pthreads - the "crashes after some time" makes sense. I suspect it IS running the C++ code: your Swift code calls some Objective-C++ wrapper code, which calls some C++, which spawns a thread, and then returns back to you and you get the data at a later time somehow.
If I were you I'd look at the C++ threading code. There's a Stackoverflow answer that might be relevant here: EINVAL on pthread_mutex. Maybe there's a bug, or the C++ code fails because it assumes Linux and you're on macOS, or something.
I also almost hate to suggest this, but depending on the size/complexity of the C++ maybe it makes sense to just rewrite it in Swift. You're going through a lot of bridging layers to call this code, feels like it could be kind of fragile (which may explain what you're seeing).
(OR compile the C++ as a separate helper app and use cross-communication like XPC or just NSTask to talk back and forth from your C++ process to your Swift process)
On my spare time, I am doing some reverse engineering games with some friends of mine and I would like to know how to prevent as much as possible asm readability. I do not want to "prevent" reverse engineering (after all it will always be possible), I just want to prevent easy understanding of functions/variables by obfuscating them in the assembly code.
For example, if I have declared a function like that in C++:
void thisFunctionReverseAString(std::string& mystring);
I would like to be sure that it will not be possible to get the names thisFunctionReverseAString and mystring from the assembly. Is there any compilation option to do that in g++ or clang++ ?
Obfuscation will only help for the source code. The executable, with no debugging information, does not contain variable names or function names.
The process of reverse engineering would involve:
Converting the executable to assembly language code.
Converting the assembly code to a high level language code.
Making sense of the sequentially named functions and variables.
For example, take an executable in FORTRAN (or compiled BASIC) and reverse engineer into C++ source code.
As others have said, there are functions to remove symbols from the Debugging version of an executable. You could start at the beginning and build an executable without symbols, often called a Release version.
Use strip to remove symbols from your executables in Linux. On Windows simple remove pdb files.
I'm just curious if anybody could help with finding good tool for the task.
I have large program in C/C++ which needs to be ported from Win32 to Linux. As "wrapping" (i.e. the most OS-sensitive) part was successfully isolated from insides of the program this task only involves going through its "internals". Some things works, some cause small compile time problems but there is one HUGE inconvenient part - macro usage.
Basically most of the internals look like this:
START_MAIN( ... )
SOME_MACRO( ... )
ANOTHER_MACRO( ... )
WRITE_SOMETHING()
END_MAIN()
This makes C/C++ look like Pascal but gives also lots of terrible pain while trying to figure out "what's wrong".
Are there ANY tools to help with parsing this kind of sources to get to the root of problems?
I'm slowly (manually) approaching "compilability" of this program but anything what could help me see through this (artificially structured) mess would be really appreciated.
If you need to manually adjust the compiling, output and stuff (i.e. looking for a customizable C++ parser), clang is a good tool to start with.
In case you just want to see the preprocessed code (with macros expanded), you can use compiler flags:
MSVC: add /P to C++ compiler flags (Project -> Properties -> C/C++ -> Command Line)
GCC, Clang: Add the -E compiler flag
This question about preprocessing C++ code contains some answers you might find useful.
Eclipse CDT will expand macros and even show you how many macro-evaluations were required to reach the final code that would be emitted by the preprocessor.
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_whatsnew.htm
Look at the "Macro Exploration" section.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Have you used any of the C++ interpreters (not compilers)?
Hi,
I am currently learning C++ and a beginner in programming in general. I've been trying to write some code to a few programming problems from the book I'm using. What I find is that often I make mistakes in what I write and those mistakes come up when the program is run. Its usually quite obvious where in the program I've gone wrong when there is regular output. But in a long computation I'm often not sure why a particular code has acted a certain way. I've also looked at Python recently. Python works with an interpreter, which can take any piece of Python code and compute its output.
I was wondering if there was something similar for C++. Right now when I want to check a line or block of code I have to comment out a lot, save it, compile it, and then run it from a command line. And I have to do that many times for a single error until I've solved it. Is there a way to type code into an active terminal which would run code and show me output? What would be better still would be a way to select a block of code (like you select text) or multiple blocks (to see how a function is being handled) within the IDE and click run to run just that block of code and see its output without having comment out irrelevant lines or to save the file. The compiled code could just reside in memory.
CINT is a c & C++ interpretter that accepts nearly all valid C++. Unfortunately many Linux distros do not offer it, and you'll probably have to build it from source... and that is a non-trivial task.
Typically a debugger is used to step through code line by line, starting at a chosen breakpoint, and keep watch of all variables/values.
Unit testing is a technique to test smaller pieces of code.
A stepping debugger, as found in most IDEs will help you with this.
Here (for example) is a description of how to set the Execution point in In Visual Studio, which sounds like what you want to do.
For certain situations, the "Immediate Window" may be of use to you. It allows you to type in expressions to evaluate immediately.
Rather than just running individual lines independently, or relying on print statements to tell you the state of whatever variables you have decided to print, you can use the debugger to run to the point of interest (where you will have set a breakpoint), then you can examine the state of any in-scope variables, or even alter the normal flow of the program.
There are some solutions that try to do this - the ones I know are Ch and TextTransformer.
However, I doubt that this works very well. C++ is not at all designed to run as an interpreted language.
One of the problems is that C++ is very, very hard to parse. And this makes it very hard to provide certain types of tools that are usual for other languages. For example, I don't think there is any C++ refactoring tool that really works well.
C++ is a compiled language not like python. But there are few c/c++ interpreters out there but not sure about their features. Check these out: Ch interpreter and CINT
If you really want to learn c++ please do not use the c/c++ interpreters.
If you insist on using a interactive interpreter there is since a long time CINT which is the default interpreter used in the ROOT project. It got better over the years, but still has only limited capabilities when dealing with templates. Also, there is a move to replace it with a JIT compiling interpreter based on clang inside the ROOT project.
If I were you I would learn how to run compiler and an interactive debugger like suggested in some comments already.
I have some numeric code that I need to convert to C or C++. I tried using f2c, but it won't work on the Fortran code. f2c complains because the code uses C style preprocessor directives (#include).
The code's readme states that it is Fortran77, that works with the fort77 linker, that would expand those includes.
Does anyone know how to successfully convert this code?
My last resort is to write a simple preprocessor to expand those includes and then feed the code to f2c.
Note: I´m working in a Windows/Visual C++ environment here, so any gcc shenanigans would probably be more trouble than they are worth...
I worked in an engineering research group for many years. We never had good luck doing automated conversions from Fortran to C. The code was not particularly understandable and it was hard to maintain. Our best luck was using the Fortran code as a template for the algorithm and doing a re-implementation for anything that we expected to continue using. Alternatively, you could update the Fortran to use more modern Fortran constructs and get a lot of the same value that you would get from moving to C/C++. We also had some success calling Fortran routines from C, although the calling convention differences sometimes made things difficult.
This might be is going out a bit on a limb, but have you considered that since perhaps you're using C-style includes, you could actually run the C preprocessor on the file in order to include those files? Then, you could take that output and run it through f2c.
(I am not an expert on the matter. Please downvote this if appropriate.)
You might get away with manually converting the
#include "whatsit.f90"
to
INCLUDE 'whatsit.f90'
and then attempting the f2c conversion again.
Have you no C pre-processor? On Unix, there might be a separate program, cpp, that would take the Fortran with #include directives and convert that into Fortran without #include directives. Alternatively, you could rename the source from xyz.f77 (xyz.f) to xyz.c, then run the C compiler in 'pre-processor only' mode and capture the output as the new input to the f2c program. You might have to worry about the options that eliminate #line directives in the output, etc, or you might be better off running the output through a simple filter (sed or perl spring to mind).