I have a functional LMDB that, for test purposes, currently contains only 21 key / value records. I've successfully tested inserting and reading records, and I'm comfortable with the database working as intended.
However, when I use the mdb_stat and mdb_dump utilities, I see the following output, respectively:
Status of Main DB
Tree depth: 1
Branch pages: 0
Leaf pages: 1
Overflow pages: 0
Entries: 1
VERSION=3
format=bytevalue
type=btree
mapsize=1073741824
maxreaders=126
db_pagesize=4096
HEADER=END
4d65737361676573
000000000000010000000000000000000100000000000000d81e0000000000001500000000000000ba1d000000000000
DATA=END
In particular, why would mdb_stat indicate only one entry when I have 21? Moreover, each entry comprises 1024 x 300 values of five bytes per value. mdb_dump obviously doesn't show anywhere near the 1,536,000 bytes I'd expect to see, yet the values I mdb_put() and mdb_get() on the fly are correct. Anyone know what's going on?
The relationship between an operating system's directory and an LMDB environment's data.mdb and lock.mdb files is one-to-one.
If the LMDB environment (in the OS directory) has more than one database, then the environment also contains a separate LMDB database containing all of its named databases.
The mdb_stat and mdb_dump utilities appear to contain minimal logic, so when they are fed a given directory via the command line, they appear to produce results only for the database storing database names and not the database(s) storing the actual data of interest.
4d65737361676573 is the Ascii for "Messages", which is the name of table ("sub-db" in lmdb terminology) storing the actual data in your case.
The mdb_dump command only dumps the main db by default. You can use the -s option to dump that sub-db, i.e.
mdb_dump -s Messages
or you can use the -a option to dump all the sub-dbs.
Since you are using a sub-database, the number of entries in the main database corresponds to the number of sub-databases you've created (ie just 1).
Try using mdb_stat -a. This will show you a break-down of all the sub-databases (as well as the main DB). In this breakdown it will list the number of entries for each sub-database. Here you should see your 21 entries.
I have some files named:
Mycase_xxx_x_xxx.csv
Mycase_xxx_x_xxx_xx_x.csv
Myanalysis_x_xx_xx_xxx_x_x.csv
Myattempt_xx_x_xxxx.csv
I would like the files named in the following way:
xxx_x_xxx.csv
xxx_x_xxx_xx_x.csv
x_xx_xx_xxx_x_x.csv
xx_x_xxxx.csv
In other words I would like (by Unix) to preserve all characters that are present in filenames after the first word.
Can anyone help me please?
Thank you in advance
This can be achieved using Perl's rename utility, which depending on your system, may be called rename, prename or perl-rename. On Debian and Ubuntu, it can be installed as follows:
sudo apt install rename
Note that on some systems, the command rename may be Perl's rename, while on others it may be util-linux's rename and on others it may be GNU rename. These tools are not compatible with each other.
Perl's rename tool on Debian and Ubuntu can be used as follows:
prename 's/expression/substitution/' filenames...
Or to apply to all files in the current directory:
prename 's/expression/substitution/' *
A useful feature of Perl's rename is the ability to use regular expressions (note how the supported syntax is similar to sed's syntax).
In your case, a regular expression to match the prefix of your filenames up to and including the first underscore is as follows:
^[^_]*_
This can then be substituted with an empty string to remove this part of the filename, resulting in the following command:
prename 's/^[^_]*_//' *
Before running this command, if you are unsure and would like to test that the files will be renamed how you want them, you can add the flags -vn as follows:
prename -vn 's/^[^_]*_//' *
This will not rename any files and will instead print out a list of the files which will be renamed, like so:
$ prename -vn 's/^[^_]*_//' *
Myanalysis_x_xx_xx_xxx_x_x.csv -> x_xx_xx_xxx_x_x.csv
Myattempt_xx_x_xxxx.csv -> xx_x_xxxx.csv
Mycase_xxx_x_xxx.csv -> xxx_x_xxx.csv
Mycase_xxx_x_xxx_xx_x.csv -> xxx_x_xxx_xx_x.csv
How to put functions from one object file to one special section and memory region for GCC linker?
I am building one standalone application for Xilinx MPSoC A53 processor. GNU ld from Linaro 2.27 is used. Xilinx software is Xilinx SDK 2017.4. I plan to put most code into DDR and some critical functions from one file into on-chip memory.
I checked '4.6.4.5. Input Section Example' from Using_ld_the_GNU_Linker/sections.html. So I created the following linker script. The output section '.text_ocm' is added by me.
.text_ocm : {
src/ocm_init.o(.text)
} > psu_ocm_ram_0_MEM_0
.text : {
KEEP (*(.vectors))
*(.boot)
*(.text)
*(.text.*)
*(.gnu.linkonce.t.*)
*(.plt)
*(.gnu_warning)
*(.gcc_execpt_table)
*(.glue_7)
*(.glue_7t)
*(.ARM.extab)
*(.gnu.linkonce.armextab.*)
} > psu_ddr_0_MEM_0
But I got error message. It seems there are two 'ocm_init'. But there is only one definition for 'ocm_init' in file 'src/ocm_init.c' my source code.
'Invoking: ARM v8 gcc linker'
aarch64-none-elf-gcc -Wl,-T -Wl,../src/lscript.ld -L../../a53a0_ddrsr_wfi_bsp/psu_cortexa53_0/lib -o "a53a0_ddrsr_wfi_step4_from_ddr.elf" ./src/ocm_init.o ./src/gic_setup.o ./src/helloworld.o ./src/platform.o ./src/timer.o -Wl,--start-group,-lxil,-lgcc,-lc,--end-group -Wl,--start-group,-lxil,-lmetal,-lgcc,-lc,--end-group -Wl,--start-group,-lxilpm,-lxil,-lgcc,-lc,--end-group
./src/ocm_init.o: In function `ocm_init':
C:\prj\mpsoc\v174\zcu102\a53a0_ddr\Debug/../src/ocm_init.c:1667: multiple definition of `ocm_init'
src/ocm_init.o:C:\prj\mpsoc\v174\zcu102\a53a0_ddr\Debug/../src/ocm_init.c:1667: first defined here
The linker cares about the leading ./ in some ways when matching file names, so either write
.text_ocm : {
*src/ocm_init.o(.text)
} > psu_ocm_ram_0_MEM_0
in your linker script, or reference the object file as src/ocm_init.o on your linker command line.
(It's not really intuitive why this omission causes multiple definitions, but I could reproduce your problem, and the change fixes it.)
Suppose I have function fn somewhere within the .text section of an ELF64 executable. Is there a way to know at which offset (in bytes) from the start of the ELF file the fn function is located? Note that I don't need to know at which VA it was relocated at linking time, but its position within the ELF file.
Generally yes, if you can parse the ELF file directly or combine output from tools like objdump and readelf.
More specific: You can get the offset and virtual address of your .text section with 'readelf -S file' - write those down.
Further you can list symbols with 'readelf -s file', as long your executable is not stripped, and your function is visible (not static or in an anonymous namespace) then you should find your function and the virtual address of it.
Thus you can calculate the offset via
fn symbol offset = fn symbol VA - .text VA + .text offset
Thats assuming you want to do it "offline" with common tools. Its more difficult if you dont have access to the unstripped ELF file, and since only a part of the ELF File remains in memory, probably not possible without adding some information with "offline" tricks.
simply use objdump -F option
user#phoenix-amd64:~$ objdump -D -F /opt/phoenix/i486/heap-xxx -D | grep main
08048630 <__libc_start_main#plt> (File Offset: 0x630):
8048679: e8 b2 ff ff ff call 8048630 <__libc_start_main#plt> (File
Offset: 0x630)
080487d5 <main> (File Offset: 0x7d5):
The answer by Norbert Lange works for the functions that are listed in the symbol table of the ELF file. But static functions will not be present there, so even if e.g. GDB could find them (by using DWARF debug info), readelf -s won't.
In this case, you can use GDB. For example, let's find the offset of xfce_displays_helper_normalize_crtc in /usr/bin/xfsettingsd (that was my actual use case, thus this obscure choice of an example).
$ gdb -q -ex 'p &xfce_displays_helper_normalize_crtc' -ex q xfsettingsd
Reading symbols from xfsettingsd...
Reading symbols from /usr/lib/debug/.build-id/b2/2ad9713642253d4d7a6f94acf0174ccfe3d487.debug...
$1 = (void (*)(XfceRRCrtc *, XfceDisplaysHelper *)) 0x11e80 <xfce_displays_helper_normalize_crtc>
Note that here we only load the file with GDB, don't let it start. And then use p command (print in full form) to get the address. So in my case, the function is at offset 0x11e80.
In some cases GDB will resolve the offset to virtual address even before we start or starti the program. This happens, in particular, on x86-32. In this case we can simply subtract the virtual address of the file image, given by readelf -l:
$ readelf -l /bin/sleep | grep ' VirtAddr \|\<LOAD *0x[0-9a-f]\+\>'
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000000 0x08048000 0x08048000 0x05230 0x05230 R E 0x1000
In the example above, the virtual address of the file image is 0x8048000, which would have to be subtracted from virtual address of the function if GDB happens to output it instead of the offset.
I couldn't find any reasonable answer for my specific question; I know how to deal with search of replace of the vim/sed, but how do we deal with csv in vim regarding the column mode search and replace. i.e. we have chunk of data in csv as :
automotive_bitcount,1,1,0,1,0,0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,0,0,1,0,0
automotive_bitcount,1,0,0,1,0,1,0,1,1,1,0,0,0,0,1,1,1,0,1,0,1,0,0,1,0
automotive_bitcount,2,1,0,0,0,0,1,0,1,0,1,1,0,0,0,0,0,0,1,1,1,1,0,1,0
automotive_bitcount,2,0,0,0,1,1,0,0,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0
automotive_bitcount,2,1,0,0,0,1,1,0,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1,1,1
which represents for the header:
APP_NAME, DATASET, COMPILER FLAGS#1,...,COMPILER FLAG#24
Here is the statement of the search and replace; I would like to replace those "1" in columns with the corresponding "Compiler flag options" (which I put down here) so at the nend I could have something like this structure in order to pass them to the compiler:
automotive_bitcount dataset1 -fno-guess-branch-probability -fno-ivopts -fno-tree-loop-optimize -fno-inline-functions -fno-omit-frame-pointer -falign-jumps -fselective-scheduling -fno-tree-pre -fno-move-loop-invariants
Just for the record, the 24 compiler flags are as follows (in their orders):
compilerOptionList= "-funsafe-math-optimizations -fno-guess-branch-probability -fno-ivopts -fno-tree-loop-optimize -fno-inline-functions -funroll-all-loops -fno-omit-frame-pointer -falign-jumps -fselective-scheduling -fno-inline-small-functions -fno-tree-pre ftracer -fno-move-loop-invariants -O2 -fno-tree-ter -fprefethch-loop-arrays -max-unrolled-insns -fno-inline-functions-called-once -fno-cprop-registers -finline-functions -fno-schedule -fno-align-functions -fno-tree-dce -fno-merge-constants"
The csv.vim - A Filetype plugin for csv files plugin has a substitute command that is scoped to a certain column:
:[range]Substitute [column/]pattern/string[/flags]