Combining Log4Delphi and jcl debug - delphi

At the moment I'm testing various logging framework for use in Delphi XE 3. Since using Log4Delphi made least problems concerning implementation into existing programs, I'm currently trying to get additional Informations for my logmessages. Now what I want to have are additional informations like method name and the line of code. I've already found the Jedi Code Librarys' debug functions might provide such data. Sadly I wasn't able to figure out hot to get this to work the way I want it.
As it is I'm currently using this function:
function CurrentFunctionName: string;
begin
Result := jcldebug.getlocationInfoStr(Caller(1));
end;
But while the code examples I've found provide data like this:
[004223A7] jcldebugtest.SomeProcedure (Line 10, "jcldebugtest.dpr")
All data I get when I'm trying to use it in my programs looks like this:
(00E8EF63) [0128FF63]
I don't fully understand the reason for this behavior, so it would be very nice if someone could explain to me how to do this properly and where my mistake/misunderstanding is located.

You need to go into Project->Options->Linker, and turn on the Detailed map file, and then build (not compile!) your project. The map file information is necessary to convert from raw addresses to specific locations in the code.
You can test this using the example located in the JCL\Examples\Windows\Debug\SourceLoc folder. If you build and run the SourceLocExample.dpr, clicking the "Caller()", "Address lookup", or "Stack dump" buttons will return simply the memory addresses. Then follow the instructions above to enable the detailed map file, do a Project->Build from the IDE's menu, and run the example again, clicking the same buttons and comparing the output.
You can then (optionally) use the Project->JCL Debug expert to embed the debug info into your executable instead of providing it as a separate file that needs to be distributed.

Related

Debugging a System.IO.Package out that won't open in Excel, possibly content_type.xml issue?

I'm trying to create a 2007+ Excel document (.xlsx), using nothing but VB.net and .net4.0 built-in classes. So I can't use any third party libraries, including Open XML SDK. The code already works fine for basic workbooks, multiple sheets, styles, etc. The resulting files open fine in Excel and calc etc.
Now I am trying to add pivotTables. They are a bit weird, as they are spread out in multiple files. I have created the Cache and Table in their proper "folders", added the pointer from workbook to the cache and the various related _rels entries... everything seems OK but Excel always reports "... found unreadable content in..."
The only obvious issue I can see is that the content_types.xml file in the resulting Package does not have an Override for the pivotTable. It does have one for the Cache, which I do not do in code, so I'm assuming Packaging has noticed the Cache and added a line here. I'm not clear on why the pivotTable didn't show up.
So looking for experts in Packaging that might point me in the right direction: is a missing line in content_types fatal to opening the file, and if so, how can I force the pivotTable to appear?

Get current stack trace from running process

I have an Delphi app with jdbg file inside the binary (using MakeJclDbg from JCLDebug) and I need to get the current stack trace (not necessary from an exception) outside the application, from another app. Is there any way to do it? Today we already do this mannualy using TJclTD32InfoScanner class, but that does not work with jdbg inside the binary.
According to the answer of Andre, I downloaded the source of AsmProfiler (which I already used) and used its classes TProcessSampler and TThreadSampler from units mcProcessSampler and mcThreadSampler. I was able to export this to a separated project and test the application. I want to thank Andre for the effort and well made profiler.

Attempt to load library; get "bad image" error

I've been trying to load a library into lua file. Sparing the details, as they are not really important, I have tried this many ways.
The final way, and the one I believe to be correct although I still can't get it to work, is to use "package.loadlib". See code:
ed = package.loadlib("Encode_Decode.lua", "luaopen_ed")
print(ed)
But when I run the program I get this error:
Encode_Decode.lua is either not designed to run on Windows or it
contains an error. Try installing the program again using the original
installation media or contact your system administrator or the
software vendor for support.
I know the program runs because I used it internally to test it's encoding and decoding abilities and it worked fine. I'd really prefer not moving the contents of the library over as my main lua file is crowded as it is. I will if I have to though.
Yes it is in the main folder. I've also tried changing the extension of the library file into a .dll, with the same error.
What am I doing wrong?
I apologize in advance if this is a duplicate, I did my best to research this problem as thoroughly as I could. But to be honest it's almost 3 AM and I've been searching for almost an hour.
Stupid beginner mistake, used the wrong syntax.
require("Encode_Decode")
print(dec("bnVs")) --returns "nul"
package.loadlib is used for loading shared libraries; i.e. .dll or .so files. You're passing a .lua file to it, so Windows attempts to load it as a .dll and fails when it can't.
To load Lua source code, you can use dofile. Alternatively, you can use require, which is a bit more complex, but handles loading modules only once and works with both Lua and C modules.

How can I find opencv functions source code?

I am new to opencv and I am using opencv for windows. How can I see the source code for a specific function of an opencv library ? I just one want to get an idea of how that specific machine vision algorithm is implemented.
You can get the OpenCV source code from https://github.com/opencv. An easy way to find the header for a function is to open an explorer window in OPENCV_HOME\build\include (where is the location where you chose to install OpenCV) and use the search box to find the header file that contains your function - this will help you know what module it is in. Then you can search in OPENCV_HOME\modules\MODULE_NAME\src to find the source of the the function. This is even easier if you install a search tool like grepWin.
Looking at the source is almost essential for finding out why those pesky OpenCV exceptions are thrown. It also means that you can answer most things about OpenCV yourself without having to ask here.
Here is a direct link to an excellent source code search, courtesy of Github. This is a very straightforward way to find the implementation and internal usages of a function or type.
All the source is now on github:
https://github.com/opencv/opencv and you can use it's search functionalities as well.
I found the answer by Drew Noakes to be the most helpful, especially given the fact that repository structures keep changing over time.
To search in the code or in other places inside a repository using a keyword, the instructions here can be followed.
What would be even easier for first-timers however, would be to simply search for a key word in the github search bar. Then the appropriate advanced search option would generate the tags described in the the earlier linked tutorial.

C++ Builder XE: find out where a specific h file is included

I'm currently porting a rather big project from C++ Builder 5 to the newest version, C++ Builder XE. It's my first experience with C++ Builder. I'm stuck with an error in a file, but I don't want to include this file anyway (it's code of a component not required anymore). I was not able to find out where and how this file is included, however. The compiler error does not give any hint at all apart from the error itself. How do you usually find out where a file is included?
The preprocessor is perfect for this. Right click on the cpp file which gives you the error in the project manager then choose "preprocess"
The output from this tells you every file and line number in the order they are processed. You can then search for the file in question, and the line above it is the file that included it.
This could conceivably be another header file as well, so it could be a long chain, but you can determine exactly where it comes from.
In the Project Options, enable the compiler's general messages. When the compiler encounters an error, you will be able to see the chain of includes that lead to the erroneous code.
If the files in question are rather sizable, a tool like Doxygen can be helpful in showing you the include dependencies (as well as call paths, etc.).
If it's just once or twice you'll have to do this, David Dean's suggestion of the preprocessor is golden.

Resources