I use so library to Packing qt, to provide customers use,( I use name "test.so" as example),
when I load test.so I create a new QApplication for Qt base
when I unload test.so I delete the QApplictaion,
In next time
when I try load test.so in The second time, I new QApplication .
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication *a;
QApplication *b;
a = new QApplication(argc, argv);
delete a;
a = nullptr;
b = new QApplication(argc, argv);
delete b;
b = nullptr;
return 0;
}
Thread 1 "123" received signal SIGSEGV, Segmentation fault.
0x0000fffff359ddec in deepin_platform_plugin::DHighDpi::logicalDpi(QXcbScreen*) ()
from /usr/lib/aarch64-linux-gnu/qt5/plugins/platforms/libdxcb.so
(gdb) bt
#0 0x0000fffff359ddec in deepin_platform_plugin::DHighDpi::logicalDpi(QXcbScreen*) ()
at /usr/lib/aarch64-linux-gnu/qt5/plugins/platforms/libdxcb.so
#1 0x0000fffff359d32c in deepin_platform_plugin::DHighDpi::pixelDensity(QXcbScreen*) ()
at /usr/lib/aarch64-linux-gnu/qt5/plugins/platforms/libdxcb.so
#2 0x0000fffff751aecc in QHighDpiScaling::screenSubfactor(QPlatformScreen const*) () at /lib/aarch64-linux-gnu/libQt5Gui.so.5
#3 0x0000fffff751b6ac in QHighDpiScaling::factor(QPlatformScreen const*) () at /lib/aarch64-linux-gnu/libQt5Gui.so.5
#4 0x0000fffff74d00d8 in QPlatformScreen::deviceIndependentGeometry() const () at /lib/aarch64-linux-gnu/libQt5Gui.so.5
#5 0x0000fffff750cd4c in () at /lib/aarch64-linux-gnu/libQt5Gui.so.5
#6 0x0000fffff74cefd0 in QPlatformIntegration::screenAdded(QPlatformScreen*, bool) () at /lib/aarch64-linux-gnu/libQt5Gui.so.5
#7 0x0000fffff34047a4 in QXcbConnection::initializeScreens() () at /lib/aarch64-linux-gnu/libQt5XcbQpa.so.5
#8 0x0000fffff3405164 in QXcbConnection::QXcbConnection(QXcbNativeInterface*, bool, unsigned int, char const*) ()
at /lib/aarch64-linux-gnu/libQt5XcbQpa.so.5
#9 0x0000fffff34093b8 in QXcbIntegration::QXcbIntegration(QStringList const&, int&, char**) ()
at /lib/aarch64-linux-gnu/libQt5XcbQpa.so.5
#10 0x0000fffff3596974 in deepin_platform_plugin::DPlatformIntegration::DPlatformIntegration(QStringList const&, int&, char**) ()
at /usr/lib/aarch64-linux-gnu/qt5/plugins/platforms/libdxcb.so
#11 0x0000fffff3595f4c in DPlatformIntegrationPlugin::create(QString const&, QStringList const&, int&, char**) ()
at /usr/lib/aarch64-linux-gnu/qt5/plugins/platforms/libdxcb.so
#12 0x0000fffff74d125c in QPlatformIntegrationFactory::create(QString const&, QStringList const&, int&, char**, QString const&) ()
at /lib/aarch64-linux-gnu/libQt5Gui.so.5
#13 0x0000fffff74df7c8 in QGuiApplicationPrivate::createPlatformIntegration() () at /lib/aarch64-linux-gnu/libQt5Gui.so.5
#14 0x0000fffff74e0658 in QGuiApplicationPrivate::createEventDispatcher() () at /lib/aarch64-linux-gnu/libQt5Gui.so.5
#15 0x0000fffff707d6ec in QCoreApplicationPrivate::init() () at /lib/aarch64-linux-gnu/libQt5Core.so.5
#16 0x0000fffff74e1898 in QGuiApplicationPrivate::init() () at /lib/aarch64-linux-gnu/libQt5Gui.so.5
#17 0x0000fffff7ab554c in QApplicationPrivate::init() () at /lib/aarch64-linux-gnu/libQt5Widgets.so.5
#18 0x0000000000402ba4 in main(int, char**) (argc=1, argv=0xffffffffdc98) at ../123/main.cpp:10
(gdb)
Related
I'm trying to encrypt a large file using OpenSSL AES_set_encrypt_key & AES_cbc_encrypt functions. I've written a C++ program to encrypt a file using AES_set_encrypt_key & AES_cbc_encrypt. The contents is got from a large file. I'm allocating memory in heap and calling AES_cbc_encrypt. But I observed only 8 bytes are getting encrypted. But when I allocate memory on stack, the function is working properly. Any help is highly appreciated.
unsigned char enc_out[encsize]; //working
unsigned char *enc_out = new unsigned char[encsize];//not working
`
QByteArray WebMessages::encryption(QString e_text) {
QByteArray ba = e_text.toLatin1();
char *encinput = strdup(ba.constData());
const int UserDataSize = strlen(encinput);
unsigned char *test2 = new unsigned char[UserDataSize];
for (int i = 0; i < UserDataSize; i++) {
test2[i] = encinput[i];
// qDebug() << test2[i];
}
int keylength = 128;
unsigned char aes_key[] = "";
unsigned char iv_enc[] = "";
unsigned char iv_dec[] = "";
const int encsize =
((UserDataSize + AES_BLOCK_SIZE) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
qDebug() << "$$$$$$$$$$$" << UserDataSize << AES_BLOCK_SIZE << encsize
<< sizeof(unsigned char *); //1481 16 1488 8
unsigned char enc_out[encsize];
// unsigned char *enc_out = new unsigned char[encsize];
AES_KEY enc_key;
AES_set_encrypt_key(aes_key, keylength, &enc_key);
AES_cbc_encrypt(test2, enc_out, UserDataSize, &enc_key, iv_enc,
AES_ENCRYPT);
qDebug() << "enc_out" << enc_out << sizeof(enc_out);
}
`
I have compiled a cpp code and downloaded it to Arduino Uno for blinking an LED. The code works fine.
However, when I convert it to .ll and from .ll to an object file then hex and upload, the code stops working. No LED blinks by the Arduino.
If I address the ports directly:
typedef unsigned char uint8_t;
typedef uint8_t * volatile port_type;
const port_type portB = (port_type) 0x25;
const port_type ddrB = (port_type) 0x24;
it will work fine but if I initialize port addressed via global constructor, it does not work:
int getPortB() {return 0x25;}
int getDdrB() {return 0x24;}
const port_type portB = (port_type) getPortB();
const port_type ddrB = (port_type) getDdrB();
This is because that global constructor is not called at all. If I call it from main function via
call addrspace(1) void #global_var_init()
it will work.
I use the following commands to compile and download the ll file to the Arduino uno:
llvm-as-9 blink1.ll -o blink1.bc
llc-9 -filetype=obj blink1.bc
avr-g++ -mmcu=atmega328p blink1.o -o blink1
avr-objcopy -O ihex -R .eeprom blink1 blink1.hex
avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyUSB0 -b 115200 -U flash:w:blink1.hex
blink1.ll
; ModuleID = 'blink1.cpp'
source_filename = "blink1.cpp"
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
target triple = "avr"
#portB = dso_local global i8* null, align 1
#ddrB = dso_local global i8* null, align 1
#llvm.global_ctors = appending global [1 x { i32, void () addrspace(1)*, i8* }] [{ i32, void () addrspace(1)*, i8* } { i32 65535, void () addrspace(1)* #global_var_init, i8* null }]
; Function Attrs: noinline
define internal void #global_var_init() addrspace(1) {
%1 = inttoptr i16 37 to i8*
store volatile i8* %1, i8** #portB, align 1
%2 = inttoptr i16 36 to i8*
store volatile i8* %2, i8** #ddrB, align 1
ret void
}
; Function Attrs: noinline nounwind optnone
define dso_local void #delay_500ms() addrspace(1) {
call addrspace(0) void asm sideeffect "ldi r19, 150 \0A\09ldi r20, 128 \0A\09ldi r23, 41 \0A\09L1: \0A\09dec r20 \0A\09brne L1 \0A\09dec r19 \0A\09brne L1 \0A\09dec r23 \0A\09brne L1 \0A\09", ""() #3, !srcloc !2
ret void
}
; Function Attrs: noinline norecurse nounwind optnone
define dso_local i16 #main() addrspace(1) {
; call addrspace(1) void #global_var_init()
%1 = alloca i16, align 1
store i16 0, i16* %1, align 1
%2 = load volatile i8*, i8** #ddrB, align 1
store i8 32, i8* %2, align 1
br label %3
3: ; preds = %0, %3
%4 = load volatile i8*, i8** #portB, align 1
store i8 32, i8* %4, align 1
call addrspace(1) void #delay_500ms()
%5 = load volatile i8*, i8** #portB, align 1
store i8 0, i8* %5, align 1
call addrspace(1) void #delay_500ms()
br label %3
}
!0 = !{i32 1, !"wchar_size", i32 2}
!1 = !{!"clang version 9.0.1-+20210314105943+c1a0a213378a-1~exp1~20210314220516.107 "}
!2 = !{i32 1296, i32 1313, i32 1338, i32 1362, i32 1377, i32 1397, i32 1416, i32 1436, i32 1455, i32 1475, i32 1494}
Is this an LLVM bug or am I doing a mistake?
I am running a program and it is printing all the printf statements on console.
But when I try to redirect them to any file using '>',the file gets created but there in no output of the program in the file.
Please help
When I run the below code in console:
#include <stdio.h>
#include <math.h>
#include <sys/time.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
double time_diff(struct timeval x , struct timeval y);
struct timeval initial;
long sno=0;
void *process1 (void *sleepTimeForP1);
void *process2 (void *sleepTimeForP2);
pthread_mutex_t lock;
int main()
{
gettimeofday(&initial , NULL);
pthread_t trd1,trd2;
int thread1,thread2;
int var1;
int var2;
int *sleepTimeForP1;
int *sleepTimeForP2;
var1=rand()%9+1;
sleepTimeForP1=&var1;
var2=rand()%9+1;
sleepTimeForP2=&var2;
printf("S No.\tThread Number\tItem\tTime(usec)\n");
thread1=pthread_create(&trd1,NULL,process1,(void *)sleepTimeForP1);
thread2=pthread_create(&trd2,NULL,process2,(void *)sleepTimeForP2);
pthread_join(trd1, NULL);
pthread_join(trd2, NULL);
printf("pthread1 = %d\n",thread1);
printf("pthread2 = %d\n",thread2);
return 0;
}
double time_diff(struct timeval x , struct timeval y)
{
double x_ms , y_ms , diff;
x_ms = (double)x.tv_sec*1000000 + (double)x.tv_usec;
y_ms = (double)y.tv_sec*1000000 + (double)y.tv_usec;
diff = (double)y_ms - (double)x_ms;
return diff;
}
void *process1 (void *sleepTimeForP1)
{
int *tsleepTimeForP1 = (int *)sleepTimeForP1;
struct timeval end;
while(1)
{
pthread_mutex_lock(&lock);
sno++;
gettimeofday(&end , NULL);
printf("%ld\t1\t\t1.1\t%.0lf\n",sno,time_diff(initial, end));
sno++;
gettimeofday(&end , NULL);
printf("%ld\t1\t\t1.2\t%.0lf\n",sno,time_diff(initial, end));
pthread_mutex_unlock(&lock);
sleep(1);
}
}
void *process2 (void *sleepTimeForP2)
{
int *tsleepTimeForP2 = (int *)sleepTimeForP2;
struct timeval end;
while(1)
{
pthread_mutex_lock(&lock);
sno++;
gettimeofday(&end , NULL);
printf("%ld\t2\t\t2.1\t%.0lf\n",sno,time_diff(initial, end));
sno++;
gettimeofday(&end , NULL);
printf("%ld\t2\t\t2.2\t%.0lf\n",sno,time_diff(initial, end));
pthread_mutex_unlock(&lock);
sleep(1);
}
}
It give me the below output:
S No. Thread Number Item Time(usec)
1 1 1.1 320
2 1 1.2 438
3 2 2.1 506
4 2 2.2 586
5 1 1.1 1000592
6 1 1.2 1000629
7 2 2.1 1000714
8 2 2.2 1000740
9 1 1.1 2000820
10 1 1.2 2000927
11 2 2.1 2000998
12 2 2.2 2001099
13 1 1.1 3001165
14 1 1.2 3001285
15 2 2.1 3001355
16 2 2.2 3001441
17 1 1.1 4001518
18 1 1.2 4001635
19 2 2.1 4001706
20 2 2.2 4001798
21 1 1.1 5001776
But when I do ./a.out > b.txt
I don't get any output on the console as well as in the file
When it is detected that the output is not directed to a terminal, the buffering is set to block buffering behind the scenes.
If you have waited long enough (probably for 4096 bytes of output to be generated), then the whole output would appear in bulk.
To solve this, you can either use fflush(stdout); after every printf(); or force the buffering mode explicitly to line buffering at the beginning with setlinebuf(stdout);.
Check out the manpage of setlinebuf() for further info.
I will be giving some pointers. Read the Linux Programming Book, to understand what is really happening.
I have added an fflush(stdout) after the relevant printf() statements of your code, i.e. line 32,65,85.
Once this is done, you will get the desired output. Now try to understand that why this kind of behavior occurs and why an explicit fflush() is required? I believe there should be some effort from the Question poster to understand the problem and to post a Minimal Complete Verifiable Example
Full Code:
#include <stdio.h>
#include <math.h>
#include <sys/time.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
double time_diff(struct timeval x , struct timeval y);
struct timeval initial;
long sno=0;
void *process1 (void *sleepTimeForP1);
void *process2 (void *sleepTimeForP2);
pthread_mutex_t lock;
int main()
{
gettimeofday(&initial , NULL);
pthread_t trd1,trd2;
int thread1,thread2;
int var1;
int var2;
int *sleepTimeForP1;
int *sleepTimeForP2;
var1=rand()%9+1;
sleepTimeForP1=&var1;
var2=rand()%9+1;
sleepTimeForP2=&var2;
printf("S No...\tThread Number\tItem\tTime(usec)\n");
fflush(stdout);
thread1=pthread_create(&trd1,NULL,process1,(void *)sleepTimeForP1);
thread2=pthread_create(&trd2,NULL,process2,(void *)sleepTimeForP2);
pthread_join(trd1, NULL);
pthread_join(trd2, NULL);
printf("pthread1 = %d\n",thread1);
printf("pthread2 = %d\n",thread2);
return 0;
}
double time_diff(struct timeval x , struct timeval y)
{
double x_ms , y_ms , diff;
x_ms = (double)x.tv_sec*1000000 + (double)x.tv_usec;
y_ms = (double)y.tv_sec*1000000 + (double)y.tv_usec;
diff = (double)y_ms - (double)x_ms;
return diff;
}
void *process1 (void *sleepTimeForP1)
{
int *tsleepTimeForP1 = (int *)sleepTimeForP1;
struct timeval end;
while(1)
{
pthread_mutex_lock(&lock);
sno++;
gettimeofday(&end , NULL);
printf("%ld\t1\t\t1.1\t%.0lf\n",sno,time_diff(initial, end));
sno++;
gettimeofday(&end , NULL);
printf("%ld\t1\t\t1.2\t%.0lf\n",sno,time_diff(initial, end));
fflush(stdout);
pthread_mutex_unlock(&lock);
sleep(1);
}
}
void *process2 (void *sleepTimeForP2)
{
int *tsleepTimeForP2 = (int *)sleepTimeForP2;
struct timeval end;
while(1)
{
pthread_mutex_lock(&lock);
sno++;
gettimeofday(&end , NULL);
printf("%ld\t2\t\t2.1\t%.0lf\n",sno,time_diff(initial, end));
sno++;
gettimeofday(&end , NULL);
printf("%ld\t2\t\t2.2\t%.0lf\n",sno,time_diff(initial, end));
fflush(stdout);
pthread_mutex_unlock(&lock);
sleep(1);
}
}
The code simply allocates memory for a matrix and uses non-blocking procedure to send the matrix from rank 0 to rank 1. It works fine for a smaller matrix size (1024). But it results in segmentation fault with a larger size (16384);
Below is the code
double **A;
int i,j,size,rankid,rankall;
size = 16384;
MPI_Request reqr,reqs;
MPI_Status star,stas;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD,&rankall);
MPI_Comm_rank(MPI_COMM_WORLD,&rankid);
A = (double**)calloc(size,sizeof(double*));
for(i=0;i<size;i++){
A[i] = (double *)calloc(size,sizeof(double));
for(j=0;j<size;j++){
if(rankid ==0){
A[i][j] = 1;
}
}
}
if(rankid ==0){
MPI_Isend(&A[0][0],size*size,MPI_DOUBLE,1,1,MPI_COMM_WORLD,&reqs);
MPI_Wait(&reqs,&stas);
}
if(rankid ==1){
MPI_Irecv(&A[0][0],size*size,MPI_DOUBLE,0,1,MPI_COMM_WORLD,&reqr);
MPI_Wait(&reqr,&star);
}
MPI_Finalize();
debug showed
#0 0x00007FFFF7947093 in ?? () From /1ib/x86_64-1inux-gnu/libc.so.6
#1 0x000000000043a5B0 in MPID_Segment_contig_m2m ()
#2 0x00000000004322cb in MPID_Segment_manipulate ()
#3 0x000000000043a?Ba in MPID_Segment_pack ()
#4 0x000000000042BB99 in lmt_shm_send_progress ()
#5 0x000000000042?e1F in MPID_nem_lmt_shm_start_send ()
#6 0x0000000000425aFF in pkt_CTS_handler ()
#? 0x000000000041Fb52 in MPIDI_CH3I_Progress ()
#8 0x0000000000405Bc1 in MPIR_Wait_impl ()
#9 0x000000000040594e in PMPI_Wait ()
#10 0x0000000000402ea5 in main (argc=1,argv=0x7fffffffe4a8)
at ./simpletest.c:26
I am trying to do sort key-value pairs with qsort. Every proc reads in files with filenames as the proc ids. MPI_Gather sends all the read values to proc 0, which sorts the keys and stores the key-val pairs in a file called "Output". The gather however, does not seem to work. Any help is appreciated. Thanks!
I run the code as
mpirun -np 3 ./a.out
and my input files are:
File "0":
21 bbbb
2119 iiii
120 hhhh
File "1":
40 dddd
10 aaaa
100 gggg
File "2":
32 cccc
44 eeee
99 ffff
And the code is:
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#define BUFSIZE 3
#define BUFLEN 255
struct keyval{
int key;
char val[BUFLEN];
};
typedef struct keyval keyval_s;
typedef int (*compareptr)(const void*, const void*);
int compare (keyval_s * a, keyval_s * b)
{
return ( a->key - b->key );
}
int main (int argc, char *argv[])
{
int values[BUFSIZE];
keyval_s kv[BUFSIZE], *recv;
int n, i=0, temp;
FILE *in, *out;
int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
char filename[20];
char data[20];
if(rank ==0){
recv = (keyval_s *) malloc (size*BUFSIZE*sizeof(keyval_s));
}
sprintf(filename, "%d", rank);
in=fopen(filename,"r");
while(fscanf(in,"%d %s",&kv[i].key, kv[i].val) != EOF){
printf("Read key %d, data %s from file\n", kv[i].key, kv[i].val);
i++;
}
MPI_Gather(kv,BUFSIZE,MPI_BYTE,recv,BUFSIZE,MPI_BYTE,0,MPI_COMM_WORLD);
if(rank==0){
qsort ((void*)&kv, BUFSIZE, sizeof(keyval_s),(compareptr) compare);
out=fopen("Output","w");
for (n=0; n<BUFSIZE*size; n++)
fprintf (out,"%d %s\n",recv[n].key, recv[n].val);
free(recv);
fclose(out);
}
fclose(in);
return 0;
}
The size of the data in MPI_Gather is incorrect. It should be
MPI_Gather(kv,
sizeof(keyval_s)*BUFSIZE,
MPI_BYTE,
recv,
sizeof(keyval_s)*BUFSIZE,
MPI_BYTE,
0,
MPI_COMM_WORLD);
Note that the recvcount parameter in MPI_Gather is for a message from a single rank, not the total size of the gathered data.